Skip to main content

InputSource

Enum InputSource 

Source
pub enum InputSource {
    Text(String),
    AnchoredText {
        text: String,
        anchor: String,
    },
    Reader(Box<dyn Read + 'static>),
}
Expand description

Owned input that can be fed into the YAML parser.

This is primarily used by the include resolver: it can return either fully-owned in-memory text, or a fully-owned streaming reader.

Variants§

§

Text(String)

Owned text.

§

AnchoredText

Owned YAML text together with the name of an anchor to extract from it.

This is mainly intended for resolvers that support include specs such as path/to/file.yaml#anchor_name. In that case, the resolver still receives the full include spec via IncludeRequest::spec, splits the file part from the fragment itself, reads the target document, and returns:

let source = InputSource::AnchoredText {
    text: "defaults: &defaults\n  enabled: true\nfeature: *defaults\n".to_owned(),
    anchor: "defaults".to_owned(),
};

During parsing, serde-saphyr will parse text, find the node tagged with &defaults, and replay only that anchored node as the included value. Conceptually, this makes:

settings: !include config.yaml#defaults

behave as if settings directly contained the YAML node anchored as &defaults inside config.yaml.

Use InputSource::Text when the whole document should be included, and use InputSource::AnchoredText only when you want the include to resolve to a specific anchored fragment.

Fields

§text: String
§anchor: String
§

Reader(Box<dyn Read + 'static>)

Owned reader (streaming).

Implementations§

Source§

impl InputSource

Source

pub fn from_string(s: String) -> Self

Source

pub fn from_reader<R>(r: R) -> Self
where R: Read + 'static,

Trait Implementations§

Source§

impl Debug for InputSource

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, 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.