Skip to main content

Layout

Enum Layout 

Source
pub enum Layout {
    Lines,
    Columns,
    Compact,
}
Expand description

What a removal leaves behind in place of the comment.

The choice is only about the hole: no layout moves a byte the comment did not cover, except where the hole itself would say something. That happens in one place, and it is YAML.

A block scalar decides where its body ends from the lines below it (YAML 1.2.2, 8.1.1), so a whole-line comment under a body is what terminates it — and the hole a removal would leave on that line is read back as content. A line of spaces as wide as the comment, which columns writes, is indented at least as deep as the body whenever the comment was wide enough; an empty line, which lines writes, is content under |+ and >+, which keep every empty line trailing a body (8.1.1.2). So in YAML a whole-line comment sitting in the run of blank and comment lines under a block scalar body is removed by taking its whole line, terminator and all, under every layout: lines gives up that line’s number and columns its columns, rather than give up the value. Under |+ and >+ the removal also takes the blank lines the comment was sheltering — they are content the moment it is gone — and never the blank lines above the first comment, which were content already.

Variants§

§

Lines

The default. The line terminators inside the comment are kept, so every following line keeps its number, and a comment with code on both sides leaves a single space so the two tokens stay apart. The YAML exception above is the one place a line does not keep its number.

§

Columns

As Self::Lines, but the comment is replaced by spaces of the same display width, so every following column on the line keeps its number as well. Tabs are expanded to the next multiple of eight. A line of spaces under a YAML block scalar body is indented into it, so the YAML exception above applies here too — and reaches further, because it applies whatever the block scalar chomps.

§

Compact

As Self::Lines, except that a line which held nothing but a removed comment goes away instead of staying behind as a blank one, and the whitespace a removal would leave at the end of a line is trimmed away with it.

Code keeps its own lines. A comment that shared a line with code leaves that line, its terminator and its CRLF or LF style exactly as they were, so a comment running across several lines with code before or after it closes up to one line rather than joining two statements. A surviving line keeps the ending it had in the source — the same LF or CRLF, from inside the comment if that is where it was — or no ending at all if the file stopped there without one.

Being alone on a line is judged from the original bytes, so a line holding two comments and nothing else keeps its terminator: neither comment was alone on it.

Implementations§

Source§

impl Layout

Source

pub const ALL: [Self; 3]

Every CLI-visible layout.

Source

pub const fn as_str(self) -> &'static str

The canonical name, identical to the serde representation.

Source

pub const fn aliases(self) -> &'static [&'static str]

Accepted spellings besides Self::as_str, already case-folded.

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

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 Copy for Layout

Source§

impl Debug for Layout

Source§

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

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

impl Default for Layout

Source§

fn default() -> Layout

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Layout

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Display for Layout

Source§

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

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

impl Eq for Layout

Source§

impl FromStr for Layout

Source§

type Err = String

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

fn from_str(value: &str) -> Result<Self, Self::Err>

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

impl Hash for Layout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Layout

Source§

fn eq(&self, other: &Layout) -> 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 Layout

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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

impl StructuralPartialEq for Layout

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> 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 = !

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.