Skip to main content

ObjView

Struct ObjView 

Source
pub struct ObjView<'lean, 'a> { /* private fields */ }
Expand description

Borrowed, allocation-free inspection view over an existing Lean object.

This is the host-facing boundary for Lean’s scalar/nullary and constructor-object representation. Callers can ask whether a value is scalar-tagged, read a scalar constructor tag, or narrow to CtorView before reading constructor header and scalar-tail fields. The view never transfers ownership and never exposes the underlying lean_object*.

Implementations§

Source§

impl<'lean, 'a> ObjView<'lean, 'a>

Source

pub fn is_scalar(&self) -> bool

Whether the object is Lean’s scalar-tagged pointer form.

Source

pub fn scalar_payload(&self, label: &str) -> LeanResult<usize>

Read the payload of a scalar-tagged object.

This is the representation Lean uses for nullary-only inductive values and for some small primitive values (Nat, Bool, Unit in boxed positions). The caller supplies label only for the error message; it is not touched on the success path.

§Errors

Returns a conversion error if the object is heap-allocated.

Source

pub fn sum_tag(&self) -> LeanResult<u8>

Read a sum-constructor tag encoded either as a scalar nullary tag or as a heap constructor tag.

This matches Lean’s mixed-inductive ABI rule: nullary constructors can be scalar-tagged, while constructors with fields are heap ctors. The returned tag is the Lean declaration-order constructor index.

§Errors

Returns a conversion error if the object is heap-allocated but is not a constructor, or if a scalar payload does not fit in u8.

Source

pub fn ctor(&self) -> LeanResult<CtorView<'lean, 'a>>

Narrow this object to a heap-constructor view.

§Errors

Returns a conversion error if the object is scalar-tagged or is a non-constructor heap object.

Source

pub fn ctor_shape( &self, expected_tag: u8, expected_num_object_fields: usize, label: &str, ) -> LeanResult<CtorView<'lean, 'a>>

Narrow this object to a constructor with the expected tag and object-slot count.

This is the common generated-result shape check. It validates the constructor tag and object-field arity before any caller reads scalar-tail values or consumes fields through take_ctor_objects.

§Errors

Returns a conversion error if the object is not a constructor, or if the constructor tag or object-field count differs.

Auto Trait Implementations§

§

impl<'lean, 'a> !Send for ObjView<'lean, 'a>

§

impl<'lean, 'a> !Sync for ObjView<'lean, 'a>

§

impl<'lean, 'a> Freeze for ObjView<'lean, 'a>

§

impl<'lean, 'a> RefUnwindSafe for ObjView<'lean, 'a>

§

impl<'lean, 'a> Unpin for ObjView<'lean, 'a>

§

impl<'lean, 'a> UnsafeUnpin for ObjView<'lean, 'a>

§

impl<'lean, 'a> UnwindSafe for ObjView<'lean, '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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more