Enum valuable::TupleDef [−][src]
#[non_exhaustive]
pub enum TupleDef {
Static {
fields: usize,
},
Dynamic {
fields: (usize, Option<usize>),
},
}
Expand description
The number of fields and other tuple-level information.
Returned by Tuplable::definition()
, TupleDef
provides the caller with
information about the tuple’s definition.
This includes the number of fields contained by the tuple.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Static
Fields
This variant is marked as non-exhaustive
fields: usize
The number of fields contained by the tuple.
The tuple is statically-defined, all fields are known ahead of time.
Static tuple implementations are provided by the crate.
Examples
A statically defined tuple.
use valuable::{Tuplable, TupleDef};
let tuple = (123, "hello");
match tuple.definition() {
TupleDef::Static { fields, .. } => {
assert_eq!(2, fields);
}
_ => unreachable!(),
};
Dynamic
Fields
This variant is marked as non-exhaustive
The tuple is dynamically-defined, not all fields are known ahead of time.
Examples
use valuable::{Tuplable, TupleDef, Valuable, Value, Visit};
struct MyTuple;
impl Valuable for MyTuple {
fn as_value(&self) -> Value<'_> {
Value::Tuplable(self)
}
fn visit(&self, visit: &mut dyn Visit) {
visit.visit_unnamed_fields(&[Value::I32(123)]);
visit.visit_unnamed_fields(&[Value::String("hello world")]);
}
}
impl Tuplable for MyTuple {
fn definition(&self) -> TupleDef {
TupleDef::new_dynamic((1, Some(3)))
}
}
Implementations
Create a new TupleDef::Static
instance
This should be used when the tuple’s fields are fixed and known ahead of time.
Examples
use valuable::TupleDef;
let def = TupleDef::new_static(2);
Create a new TupleDef::Dynamic
instance.
This is used when the tuple’s fields may vary at runtime.
Examples
use valuable::TupleDef;
let def = TupleDef::new_dynamic((2, Some(10)));
Returns true
if the tuple is statically defined.
Examples
With a static tuple
use valuable::TupleDef;
let def = TupleDef::new_static(2);
assert!(def.is_static());
With a dynamic tuple
use valuable::TupleDef;
let def = TupleDef::new_dynamic((2, None));
assert!(!def.is_static());
Returns true
if the tuple is dynamically defined.
Examples
With a static tuple
use valuable::TupleDef;
let def = TupleDef::new_static(2);
assert!(!def.is_dynamic());
With a dynamic tuple
use valuable::TupleDef;
let def = TupleDef::new_dynamic((2, None));
assert!(def.is_dynamic());