#[non_exhaustive]pub enum TupleDef {
#[non_exhaustive] Static {
fields: usize,
},
#[non_exhaustive] 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
#[non_exhaustive]Static
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!(),
};Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Dynamic
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)))
}
}Fields
This variant is marked as non-exhaustive
Implementations§
Source§impl TupleDef
impl TupleDef
Sourcepub const fn new_static(fields: usize) -> TupleDef
pub const fn new_static(fields: usize) -> TupleDef
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);Sourcepub const fn new_dynamic(fields: (usize, Option<usize>)) -> TupleDef
pub const fn new_dynamic(fields: (usize, Option<usize>)) -> TupleDef
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)));Sourcepub fn is_unit(&self) -> bool
pub fn is_unit(&self) -> bool
Returns true if self represents the unit tuple.
§Examples
With the unit tuple
use valuable::Tuplable;
let tuple: &dyn Tuplable = &();
assert!(tuple.definition().is_unit());When not the unit tuple.
use valuable::Tuplable;
let tuple: &dyn Tuplable = &(123,456);
assert!(!tuple.definition().is_unit());Sourcepub fn is_static(&self) -> bool
pub fn is_static(&self) -> bool
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());Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
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());