Skip to main content

Ty

Enum Ty 

Source
pub enum Ty {
    Text,
    Number,
    Bool,
    Bytes,
    Image,
    Document,
    Json,
    List(Box<Ty>),
    Record(BTreeMap<String, Ty>),
}
Expand description

The shape of a value flowing through a pipeline.

Deliberately small. This exists to catch the mistake that actually happens when blocks are composed — one block emitting a summary string into another expecting a list of chunks — not to be a general-purpose type system. A richer one would need inference, and inference over a language with no expressions is machinery without a use. Written and read as a compact string — text, [text], {path: text} — rather than as a nested tagged object.

Two reasons, and the second is the one that forced it. It reads well in an error message and in a spec, so one syntax serves the wire, the diagnostics, and the DSL. And a recursive enum serialized structurally makes serde’s generic serializer recurse deeply enough to blow rustc’s recursion limit in the guest crate — which would have meant every block author adding #![recursion_limit] to work around a detail of this type.

Variants§

§

Text

A UTF-8 string.

§

Number

A JSON number, integral or fractional.

One variant rather than an int/float pair: JSON itself does not distinguish them, so a block returning 3 where 3.0 was meant would fail a check that exists only in the type system and nowhere in the data. Where the distinction matters downstream — a Parquet column type, say — it is decided by looking at the values, which is the only place the information actually exists.

§

Bool

A JSON boolean.

§

Bytes

Opaque bytes, base64-encoded on the wire.

§

Image

A handle naming an image the host holds.

§

Document

A handle naming a paged document.

§

Json

Any JSON value. The top type: everything is assignable to it.

An escape hatch, and one worth using sparingly — a pipeline of Json seams typechecks unconditionally, which is the same as not checking.

§

List(Box<Ty>)

An ordered sequence.

§

Record(BTreeMap<String, Ty>)

A fixed set of named fields.

A BTreeMap so that two records written in different field orders are the same type, and so error messages list fields the same way twice.

Implementations§

Source§

impl Ty

Source

pub fn assignable_to(&self, expected: &Ty) -> bool

Whether a value of this type can be fed where expected is required.

Not equality: Ty::Json accepts anything, and a record with extra fields satisfies one that needs fewer. Both directions of that matter — a block that adds a field should not break its consumer, and a block that requires a field its producer never emits should fail loudly.

Source

pub fn matches_value(&self, value: &Value) -> bool

Whether a live JSON value could plausibly be an instance of this type — a runtime counterpart to Self::assignable_to, which only ever compares two declared Tys against each other. Nothing in the host checked a block’s actual output against what it declared until this existed: a block could claim {summary: text} and return {text: "..."} and nothing downstream would notice until whatever consumed summary got null.

Deliberately permissive, not a full validator: Ty::Bytes, Ty::Image, and Ty::Document have no fixed JSON shape defined anywhere in this protocol (unlike Ty::Text/Ty::List/ Ty::Record, which map onto JSON strings/arrays/objects unambiguously) — inventing a shape for them here risks rejecting legitimate values a real block already produces. Those three, like Ty::Json, accept anything.

Source

pub fn describe(&self) -> String

A short human-readable rendering, for error messages.

Trait Implementations§

Source§

impl Clone for Ty

Source§

fn clone(&self) -> Ty

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ty

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Ty

Source§

fn deserialize<D>(d: D) -> Result<Ty, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Ty

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for Ty

Source§

impl FromStr for Ty

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Ty, <Ty as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Ty

Source§

fn eq(&self, other: &Ty) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Ty

Source§

fn serialize<S>( &self, s: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Ty

Auto Trait Implementations§

§

impl Freeze for Ty

§

impl RefUnwindSafe for Ty

§

impl Send for Ty

§

impl Sync for Ty

§

impl Unpin for Ty

§

impl UnsafeUnpin for Ty

§

impl UnwindSafe for Ty

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.