pub struct UserKey(/* private fields */);Expand description
利用者定義の形の項目の名前(crate::param::Kind::User)。Kind を Copy のまま名前で持つため、名前をプロセスの
表に 1 つだけ置いた文字列への参照にしたもの(光線ごとの微分で表を引かない)。表に足すのは準備できた形の設定の
数の項目だけ(外から来た誤った名前で増えない)。serde・表示は名前の文字列。
登録したモデルが ShapeModel::params で宣言した数の項目は、形を準備する前(系より先に変数の行を読むときなど)
から読める:
use lensbench_core::param::Kind;
use lensbench_core::plugin::{Config, ParamSpec, ParamType};
use lensbench_core::usershape::{ShapeInstance, ShapeModel};
use std::sync::Arc;
struct Bump;
impl ShapeModel for Bump {
fn name(&self) -> &str { "doc_bump" }
fn params(&self) -> Vec<ParamSpec> {
vec![ParamSpec::new("height", ParamType::Num, None, "mm", "")]
}
fn prepare(&self, _: &Config) -> lensbench_core::Result<Arc<dyn ShapeInstance>> {
unimplemented!()
}
}
// 新しいプロセスで、形を何も準備していないうちは読めない
assert!(Kind::parse("u_height").is_err());
let mut ext = lensbench_core::ext::Ext::default();
ext.add_shape_model(Arc::new(Bump));
assert!(Kind::parse("u_height").is_ok());
// 宣言していない名前は表に足さない
assert!(Kind::parse("u_nothing").is_err());Implementations§
Source§impl UserKey
impl UserKey
Sourcepub fn get(name: &str) -> Option<UserKey>
pub fn get(name: &str) -> Option<UserKey>
表にある名前(登録したモデルが宣言した項目と、準備した形の設定の数の項目)。無ければ None。 読むとき(serde)も同じ表を引く:
use lensbench_core::plugin::{Config, ParamSpec, ParamType};
use lensbench_core::usershape::{ShapeInstance, ShapeModel, UserKey};
use std::sync::Arc;
struct Tilt;
impl ShapeModel for Tilt {
fn name(&self) -> &str { "doc_tilt" }
fn params(&self) -> Vec<ParamSpec> {
vec![ParamSpec::new("slope", ParamType::Num, None, "", "")]
}
fn prepare(&self, _: &Config) -> lensbench_core::Result<Arc<dyn ShapeInstance>> {
unimplemented!()
}
}
// 新しいプロセスで、登録の前は読めない
assert!(serde_json::from_str::<UserKey>("\"slope\"").is_err());
lensbench_core::ext::Ext::default().add_shape_model(Arc::new(Tilt));
let k: UserKey = serde_json::from_str("\"slope\"").unwrap();
assert_eq!((k.name(), UserKey::get("slope")), ("slope", Some(k)));
assert!(serde_json::from_str::<UserKey>("\"nothing\"").is_err());Trait Implementations§
impl Copy for UserKey
Source§impl<'de> Deserialize<'de> for UserKey
impl<'de> Deserialize<'de> for UserKey
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for UserKey
Source§impl JsonSchema for UserKey
impl JsonSchema for UserKey
Source§fn json_schema(g: &mut SchemaGenerator) -> Schema
fn json_schema(g: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl Ord for UserKey
impl Ord for UserKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Auto Trait Implementations§
impl Freeze for UserKey
impl RefUnwindSafe for UserKey
impl Send for UserKey
impl Sync for UserKey
impl Unpin for UserKey
impl UnsafeUnpin for UserKey
impl UnwindSafe for UserKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more