Interface

Struct Interface 

Source
pub struct Interface {
    pub module: String,
    pub imports: Vec<String>,
    pub types: Vec<TyDecl>,
    pub traits: Vec<TraitSig>,
    pub impls: Vec<ImplSig>,
    pub items: Vec<Item>,
}
Expand description

A module’s published signature.

Fields§

§module: String§imports: Vec<String>

The modules this contract was checked against, rendered as import lines.

A .becki is read back as a module, so a name it uses but does not declare has to be resolvable from the file itself. A published impl Priced for Book, or a bound def total[T: Priced], names a trait that may live in another module — and without the import line the reader has nothing to resolve Priced against and reports B0383, which made beck iface write a file beck check refused.

Deliberately not in Interface::digest: the digest is about the signatures published, and this is provenance for resolving the names in them. Hashing it would report an API change to every consumer when a module gained an import its contract never mentions.

§types: Vec<TyDecl>

Types in declaration order, so the rendered file is stable.

§traits: Vec<TraitSig>

The trait declarations this module owns.

§impls: Vec<ImplSig>

The impl headers this module owns — the bodies stay behind, and what crosses is that the implementation exists and what it promises. Without these, a call in an importing module has a trait and nothing to resolve it to.

§items: Vec<Item>

Implementations§

Source§

impl Interface

Source

pub fn of(program: &Program) -> Interface

Extract the interface of a checked, placed program.

Source

pub fn item(&self, name: &str) -> Option<&Item>

Source

pub fn digest(&self) -> String

A content hash of everything a downstream module can depend on.

Deliberately not a hash of the rendered file: a comment, or a change of field order in the printer, must not invalidate a build. It is a hash of the meaning.

Source

pub fn render(&self) -> String

Render the .becki file.

Source

pub fn parse( module: &str, src: &str, map: &mut SourceMap, diags: &mut Diagnostics, ) -> Interface

Read a .becki back.

The caller’s SourceMap, for the same reason crate::project gives one to every module it loads: a diagnostic about orders.becki has to point into orders.becki. A map made and dropped here would leave every diagnostic carrying a FileId the renderer resolves against somebody else’s file, which is worse than no span at all — it points confidently at an unrelated line.

Source

pub fn parse_with( module: &str, src: &str, imports: &[(String, Interface)], map: &mut SourceMap, diags: &mut Diagnostics, ) -> Interface

The same, against the interfaces of the modules this one imports.

A .becki is checked as a module, so a name it uses but does not declare needs the same thing a .beck needs: the contract of whatever declares it. A published impl Priced for Book or a bound def total[T: Priced] names a trait that may live elsewhere, and reading the file with nothing to resolve against reported B0383 — beck iface wrote a file beck check refused. crate::project has every dependency’s interface in hand by the time it reads this one, because it works in dependency order, deepest first.

Interface::parse passing none is still right for a caller that has none — comparing an old contract to a new one for --wire-compat reads signatures, and a trait it cannot resolve is reported rather than silently accepted.

Source

pub fn exports( &self, ) -> (BTreeMap<Arc<str>, TyDecl>, BTreeMap<Arc<str>, Export>)

Register this interface’s types and names in a checker’s environment.

Trait Implementations§

Source§

impl Clone for Interface

Source§

fn clone(&self) -> Interface

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Interface

Source§

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

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

impl Default for Interface

Source§

fn default() -> Interface

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

impl PartialEq for Interface

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Interface

Source§

impl StructuralPartialEq for Interface

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