Skip to main content

Interface

Struct Interface 

pub struct Interface<'a> {
    doc: Option<&'a Doc>,
    members: &'a [Member<'a>],
    name: &'a InterfaceName,
}
Expand description

A Varlink interface.

Holding an Interface proves that it follows the rules of the specification: names are unique, referenced types are declared and enums have variants.

use varlet_idl::{Doc, Field, FieldName, Interface, InterfaceName, Member, Method, Name, Type};

const ADD: Method = Method::new(
    Name::from_static("Add"),
    &[
        Field::new(FieldName::from_static("a"), Type::INT),
        Field::new(FieldName::from_static("b"), Type::INT),
    ],
    &[Field::new(FieldName::from_static("sum"), Type::INT)],
)
.with_doc(Doc::from_static("Adds numbers."));

static CALC: Interface<'static> = Interface::from_static(
    InterfaceName::from_static("org.example.calc"),
    &[Member::Method(ADD)],
);

let add = CALC
    .methods()
    .find(|method| method.name().as_str() == "Add");
assert!(add.is_some());

Fields§

§doc: Option<&'a Doc>§members: &'a [Member<'a>]§name: &'a InterfaceName

Implementations§

§

impl<'a> Interface<'a>

pub const fn doc(self) -> Option<&'a Doc>

Returns the doc comment.

pub fn errors(self) -> impl Iterator<Item = ErrorDef<'a>>

Returns the error declarations in the order they are declared.

pub const fn members(self) -> &'a [Member<'a>]

Returns the types, methods and errors in the order they are declared.

pub fn methods(self) -> impl Iterator<Item = Method<'a>>

Returns the method declarations in the order they are declared.

pub const fn name(self) -> &'a InterfaceName

Returns the interface name.

pub const fn new( name: &'a InterfaceName, members: &'a [Member<'a>], ) -> Result<Self, ValidationError<'a>>

Creates an interface from its declarations.

§Errors

Returns the first rule of the specification the declarations break.

pub fn types(self) -> impl Iterator<Item = TypeDef<'a>>

Returns the type declarations in the order they are declared.

pub const fn with_doc(self, doc: &'a Doc) -> Self

Returns the interface with the doc comment doc.

§

impl Interface<'static>

pub const fn from_static( name: &'static InterfaceName, members: &'static [Member<'static>], ) -> Self

Creates an interface from static declarations.

This is meant for const and static items, where an invalid interface fails the build. Use new for declarations that come from input.

§Panics

Panics if the declarations break a rule of the specification.

§

impl<'a> Interface<'a>

pub fn parse(input: &'a str, arena: &'a Arena) -> Result<Self, ParseError>

Available on crate feature parse only.

Parses an interface definition.

The result borrows names and doc comments from input. Lists, nested types and doc comments of several lines are stored in arena.

let arena = varlet_idl::Arena::new();
let interface = varlet_idl::Interface::parse(
    "# Adds numbers.
interface org.example.calc

method Add(a: int, b: int) -> (sum: int)",
    &arena,
)?;
assert_eq!(interface.name().as_str(), "org.example.calc");
assert_eq!(interface.methods().count(), 1);
§Errors

Returns where and why the input isn’t a valid interface definition.

The parser follows the grammar of the specification with one exception: declarations don’t need to be on separate lines, as the specification also says that whitespace is ignored.

Trait Implementations§

§

impl<'a> Clone for Interface<'a>

§

fn clone(&self) -> Interface<'a>

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
§

impl<'a> Copy for Interface<'a>

§

impl<'a> Debug for Interface<'a>

§

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

Formats the value using the given formatter. Read more
§

impl Display for Interface<'_>

§

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

Writes the interface as IDL text.

§

impl<'a> Eq for Interface<'a>

§

impl<'a> PartialEq for Interface<'a>

§

fn eq(&self, other: &Interface<'a>) -> bool

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

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

Inequality operator !=. Read more
§

impl<'a> StructuralPartialEq for Interface<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Interface<'a>

§

impl<'a> RefUnwindSafe for Interface<'a>

§

impl<'a> Send for Interface<'a>

§

impl<'a> Sync for Interface<'a>

§

impl<'a> Unpin for Interface<'a>

§

impl<'a> UnsafeUnpin for Interface<'a>

§

impl<'a> UnwindSafe for Interface<'a>

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