pub struct FieldDef {
pub name: String,
pub optional: bool,
pub default: Option<Value>,
}Expand description
Field definition with optional default value.
Represents a field in a schema with its name, whether it’s optional, and an optional default value.
§Examples
use hedl_core::schema_version::FieldDef;
use hedl_core::Value;
// Required field
let id_field = FieldDef {
name: "id".to_string(),
optional: false,
default: None,
};
// Optional field with default
let status_field = FieldDef {
name: "status".to_string(),
optional: true,
default: Some(Value::String("active".to_string().into())),
};Fields§
§name: StringThe field name.
optional: boolWhether the field is optional.
default: Option<Value>Default value if the field is omitted.
Implementations§
Source§impl FieldDef
impl FieldDef
Sourcepub fn with_default(name: impl Into<String>, default: Value) -> Self
pub fn with_default(name: impl Into<String>, default: Value) -> Self
Create a new optional field with a default value.
§Arguments
name- The field namedefault- The default value
§Examples
use hedl_core::schema_version::FieldDef;
use hedl_core::Value;
let field = FieldDef::with_default("active", Value::Bool(true));
assert!(field.optional);
assert_eq!(field.default, Some(Value::Bool(true)));Trait Implementations§
impl StructuralPartialEq for FieldDef
Auto Trait Implementations§
impl Freeze for FieldDef
impl RefUnwindSafe for FieldDef
impl Send for FieldDef
impl Sync for FieldDef
impl Unpin for FieldDef
impl UnwindSafe for FieldDef
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,
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