pub struct Layout { /* private fields */ }Expand description
A facet’s field layout: names in wire order, with the type each binds as.
Learned once. The names are the metadata’s own, in the order the records carry them, and that order is the position a binder addresses fields by for the rest of the run.
Obtain one with Layout::resolve, which prefers what the dataset
declares over what one record happens to show.
Implementations§
Source§impl Layout
impl Layout
Sourcepub fn resolve<V>(view: &V) -> Result<Layout, BindError>where
V: TestDataView + ?Sized,
pub fn resolve<V>(view: &V) -> Result<Layout, BindError>where
V: TestDataView + ?Sized,
The layout of a profile’s metadata_content records, from the
strongest source the dataset offers.
In order: the metadata_layout facet, the content slab’s
layout namespace, its schema namespace, and last the first
record. source says which was used, and
unproven names the fields whose type the
source could not establish.
A declared layout is then checked against the facet’s first record: the same field names in the same order, and no value of a type its field does not have. A layout that does not describe the records it is published beside is refused here, by name, rather than discovered as wrong values on a later cycle.
Costs the tail of each container consulted and one page of the content facet; nothing is downloaded whole.
use vectordata::binding::{BindType, Layout, LayoutSource};
use vectordata::formats::mnode::{MNode, MValue, TypeTag};
// The first record has no `note`; the layout says it is text.
let mut first = MNode::new();
first.insert("id".into(), MValue::Int(1));
first.insert("note".into(), MValue::Null);
write("metadata_content.slab", &[first.to_bytes()]);
let mut declared = MNode::new();
declared.insert("id".into(), MValue::default_for(TypeTag::Int));
declared.insert("note".into(), MValue::default_for(TypeTag::Text));
write("metadata_layout.slab", &[declared.to_bytes()]);
std::fs::write(dir.join("dataset.yaml"),
"name: d\nprofiles:\n default:\n metadata_content: metadata_content.slab\n metadata_layout: metadata_layout.slab\n")?;
let view = vectordata::TestDataGroup::load(dir.to_str().unwrap())?.profile("default").unwrap();
let layout = Layout::resolve(&*view)?;
assert_eq!(layout.source(), LayoutSource::LayoutFacet);
assert_eq!(layout.types(), [BindType::Int64, BindType::Text]);
assert!(layout.unproven().is_empty());Sourcepub fn from_exemplar(
record: &[u8],
source: LayoutSource,
) -> Result<Layout, BindError>
pub fn from_exemplar( record: &[u8], source: LayoutSource, ) -> Result<Layout, BindError>
A layout from a layout record: one record in which every field
is present at its type’s default value — a record’s
fingerprint — as the metadata_layout
facet and the layout namespace hold it. Any record of the
facet serves: it is fingerprinted here.
Sourcepub fn from_schema(schema: &MetadataSchema) -> Result<Layout, BindError>
pub fn from_schema(schema: &MetadataSchema) -> Result<Layout, BindError>
A layout from a metadata schema descriptor: the column names and type names a converter recorded.
A type name no tag has is refused naming the field, since a descriptor this build cannot read must not become a layout with a guessed type in it.
Sourcepub fn discover(facet: &RecordFacet) -> Result<Layout, BindError>
pub fn discover(facet: &RecordFacet) -> Result<Layout, BindError>
Learn a facet’s layout from its first record.
The weakest source, and the one resolve falls
back to when a dataset declares nothing: a field that is null in
the first record gets no type, a field that record lacks is not
in the layout at all, and an empty container gets no element
type. unproven names the fields affected.
Sourcepub fn source(&self) -> LayoutSource
pub fn source(&self) -> LayoutSource
Where this layout was learned from.
Sourcepub fn exemplar(&self) -> ANode
pub fn exemplar(&self) -> ANode
The layout as a record: every field present, in order, at its type’s default value — the layout record the dataset publishes, or the one this layout was learned as.
What a rendering codec is applied to — encoded with
anode::encode — to produce the
text one record stands for (a column list, a values tuple of
markers) before any record is read. A container whose element
type is not stated appears empty.
Sourcepub fn nullability(&self) -> &[Nullability]
pub fn nullability(&self) -> &[Nullability]
Whether each field may hold a null, by position, as the dataset
declares it. See Nullability.
Sourcepub fn position_of(&self, field: &str) -> Option<usize>
pub fn position_of(&self, field: &str) -> Option<usize>
The position of a named field.
Sourcepub fn unproven(&self) -> Vec<&str>
pub fn unproven(&self) -> Vec<&str>
The fields whose bind type this layout does not establish, by name: a container with no element type, and — in a layout inferred from a record — a field that was null there.
A declared layout may type a field as null on purpose, for a column that holds nothing; that is a statement, not a gap, and is not listed. Empty means every parameter’s type is known before the first record is bound.
Sourcepub fn check_record(&self, record: &[u8]) -> Result<(), BindError>
pub fn check_record(&self, record: &[u8]) -> Result<(), BindError>
Check that record has this layout: the same field names in
the same order, each value of a type its field admits.
A null value agrees with any field not declared never null, and a container whose element type is open on either side agrees with a container of the same kind.
Trait Implementations§
impl StructuralPartialEq for Layout
Auto Trait Implementations§
impl Forget for Layout
impl Freeze for Layoutwhere
*const u8 is !null: Freeze,
PhantomData<usize>: Freeze,
PhantomData<Bucket<String, MValue>>: Freeze,
PhantomData<String>: Freeze,
PhantomData<BindType>: Freeze,
PhantomData<Nullability>: Freeze,
impl Move for Layout
impl RefUnwindSafe for Layout
impl Send for Layout
impl Sync for Layout
impl Unpin for Layout
impl UnsafeUnpin for Layoutwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, MValue>>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<BindType>: UnsafeUnpin,
PhantomData<Nullability>: UnsafeUnpin,
impl UnwindSafe for Layout
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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