Skip to main content

Doc

Struct Doc 

#[repr(transparent)]
pub struct Doc(str);
Expand description

Doc comment of a declaration, a field or an enum variant.

The text contains the lines of the comment without the leading #, separated by \n. An empty text is a comment of one empty line. Other line breaks are rejected: written as IDL text, they would end the comment and turn the rest of the line into a declaration.

use varlet_idl::Doc;

const DOC: &Doc = Doc::from_static("Adds numbers.\n\nIt never fails.");
assert_eq!(
    DOC.lines().collect::<Vec<_>>(),
    ["Adds numbers.", "", "It never fails."]
);
assert!(Doc::new("Adds numbers.\rmethod Evil() -> ()").is_err());

Tuple Fields§

§0: str

Implementations§

§

impl Doc

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

Returns the text of the doc comment.

pub const fn from_static(text: &'static str) -> &'static Self

Checks static text like new does.

This is meant for const contexts, where invalid text fails the build. Use new for text that comes from input.

§Panics

Panics if the text contains a line break other than \n.

pub fn lines(&self) -> Split<'_, char> ⓘ

Returns the lines of the doc comment.

There is always at least one line.

pub const fn new(text: &str) -> Result<&Self, InvalidDoc>

Checks that text separates lines with \n only.

§Errors

Returns the position of the first other line break: \r, U+2028 or U+2029.

const fn check(rest: &[u8]) -> Result<(), InvalidDoc>

Checks the bytes of a text for line breaks other than \n.

const fn cast(text: &str) -> &Self

Trait Implementations§

§

impl Debug for Doc

§

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

Formats the value using the given formatter. Read more
§

impl Eq for Doc

§

impl Hash for Doc

§

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

Feeds this value into the given Hasher. Read more
§

impl Ord for Doc

§

fn cmp(&self, other: &Doc) -> Ordering

This method returns an Ordering between self and other. Read more
§

impl PartialEq for Doc

§

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

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

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

Inequality operator !=. Read more
§

impl PartialOrd for Doc

§

fn partial_cmp(&self, other: &Doc) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl StructuralPartialEq for Doc

Auto Trait Implementations§

§

impl !Sized for Doc

§

impl Freeze for Doc

§

impl RefUnwindSafe for Doc

§

impl Send for Doc

§

impl Sync for Doc

§

impl Unpin for Doc

§

impl UnsafeUnpin for Doc

§

impl UnwindSafe for Doc

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