Struct ouroboros_examples::Visibility[][src]

pub struct Visibility { /* fields omitted */ }

This struct demonstrates how visibility can be controlled. The struct is defined with the following code:

#[self_referencing(pub_extras)]
pub struct Visibility {
    private_field: Box<i32>,
    #[borrows(private_field)]
    pub public_field: &'this i32,
    #[borrows(private_field)]
    pub(crate) pub_crate_field: &'this i32,
}

By using pub_extras, the visibility of items not related to any particular field like with_mut or VisibilityBuilder is made public to match the visibility of the original struct definition. Without adding this option, these items would only be visible in the module where the struct is declared.

Implementations

impl Visibility[src]

pub fn new(
    private_field: Box<i32>,
    public_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> &'this i32,
    pub_crate_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> &'this i32
) -> Visibility
[src]

Constructs a new instance of this self-referential struct. (See also VisibilityBuilder::build()). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:

ArgumentSuggested Use
private_fieldDirectly pass in the value this field should contain
public_field_builderUse a function or closure: (private_field: &_) -> public_field: _
pub_crate_field_builderUse a function or closure: (private_field: &_) -> pub_crate_field: _

pub async fn new_async(
    private_field: Box<i32>,
    public_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Pin<Box<dyn Future<Output = &'this i32> + 'this>>,
    pub_crate_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Pin<Box<dyn Future<Output = &'this i32> + 'this>>
) -> Visibility
[src]

Constructs a new instance of this self-referential struct. (See also VisibilityAsyncBuilder::build()). Each argument is a field of the new struct. Fields that refer to other fields inside the struct are initialized using functions instead of directly passing their value. The arguments are as follows:

ArgumentSuggested Use
private_fieldDirectly pass in the value this field should contain
public_field_builderUse a function or closure: (private_field: &_) -> public_field: _
pub_crate_field_builderUse a function or closure: (private_field: &_) -> pub_crate_field: _

pub fn try_new<Error_>(
    private_field: Box<i32>,
    public_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Result<&'this i32, Error_>,
    pub_crate_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Result<&'this i32, Error_>
) -> Result<Visibility, Error_>
[src]

(See also VisibilityTryBuilder::try_build().) Like new, but builders for self-referencing fields can return results. If any of them fail, Err is returned. If all of them succeed, Ok is returned. The arguments are as follows:

ArgumentSuggested Use
private_fieldDirectly pass in the value this field should contain
public_field_builderUse a function or closure: (private_field: &_) -> Result<public_field: _, Error_>
pub_crate_field_builderUse a function or closure: (private_field: &_) -> Result<pub_crate_field: _, Error_>

pub fn try_new_or_recover<Error_>(
    private_field: Box<i32>,
    public_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Result<&'this i32, Error_>,
    pub_crate_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Result<&'this i32, Error_>
) -> Result<Visibility, (Error_, Heads)>
[src]

(See also VisibilityTryBuilder::try_build_or_recover().) Like try_new, but all head fields are returned in the case of an error. The arguments are as follows:

ArgumentSuggested Use
private_fieldDirectly pass in the value this field should contain
public_field_builderUse a function or closure: (private_field: &_) -> Result<public_field: _, Error_>
pub_crate_field_builderUse a function or closure: (private_field: &_) -> Result<pub_crate_field: _, Error_>

pub async fn try_new_async<Error_>(
    private_field: Box<i32>,
    public_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Pin<Box<dyn Future<Output = Result<&'this i32, Error_>> + 'this>>,
    pub_crate_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Pin<Box<dyn Future<Output = Result<&'this i32, Error_>> + 'this>>
) -> Result<Visibility, Error_>
[src]

(See also VisibilityAsyncTryBuilder::try_build().) Like new, but builders for self-referencing fields can return results. If any of them fail, Err is returned. If all of them succeed, Ok is returned. The arguments are as follows:

ArgumentSuggested Use
private_fieldDirectly pass in the value this field should contain
public_field_builderUse a function or closure: (private_field: &_) -> Result<public_field: _, Error_>
pub_crate_field_builderUse a function or closure: (private_field: &_) -> Result<pub_crate_field: _, Error_>

pub async fn try_new_or_recover_async<Error_>(
    private_field: Box<i32>,
    public_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Pin<Box<dyn Future<Output = Result<&'this i32, Error_>> + 'this>>,
    pub_crate_field_builder: impl for<'this> FnOnce(&'this <Box<i32> as Deref>::Target) -> Pin<Box<dyn Future<Output = Result<&'this i32, Error_>> + 'this>>
) -> Result<Visibility, (Error_, Heads)>
[src]

(See also VisibilityAsyncTryBuilder::try_build_or_recover().) Like try_new, but all head fields are returned in the case of an error. The arguments are as follows:

ArgumentSuggested Use
private_fieldDirectly pass in the value this field should contain
public_field_builderUse a function or closure: (private_field: &_) -> Result<public_field: _, Error_>
pub_crate_field_builderUse a function or closure: (private_field: &_) -> Result<pub_crate_field: _, Error_>

pub(crate) fn with_private_field<'outer_borrow, ReturnType>(
    &'outer_borrow self,
    user: impl for<'this> FnOnce(&'outer_borrow Box<i32>) -> ReturnType
) -> ReturnType
[src]

Provides limited immutable access to private_field. This method was generated because the contents of private_field are immutably borrowed by other fields.

pub(crate) fn borrow_private_field<'this>(&'this self) -> &'this Box<i32>[src]

Provides limited immutable access to private_field. This method was generated because the contents of private_field are immutably borrowed by other fields.

pub fn with_public_field<'outer_borrow, ReturnType>(
    &'outer_borrow self,
    user: impl for<'this> FnOnce(&'outer_borrow &'this i32) -> ReturnType
) -> ReturnType
[src]

Provides an immutable reference to public_field. This method was generated because public_field is a tail field.

pub fn borrow_public_field<'this>(&'this self) -> &'this &'this i32[src]

Provides an immutable reference to public_field. This method was generated because public_field is a tail field.

pub fn with_public_field_mut<'outer_borrow, ReturnType>(
    &'outer_borrow mut self,
    user: impl for<'this> FnOnce(&'outer_borrow mut &'this i32) -> ReturnType
) -> ReturnType
[src]

Provides a mutable reference to public_field. This method was generated because public_field is a tail field. No borrow_public_field_mut function was generated because Rust’s borrow checker is currently unable to guarantee that such a method would be used safely.

pub(crate) fn with_pub_crate_field<'outer_borrow, ReturnType>(
    &'outer_borrow self,
    user: impl for<'this> FnOnce(&'outer_borrow &'this i32) -> ReturnType
) -> ReturnType
[src]

Provides an immutable reference to pub_crate_field. This method was generated because pub_crate_field is a tail field.

pub(crate) fn borrow_pub_crate_field<'this>(&'this self) -> &'this &'this i32[src]

Provides an immutable reference to pub_crate_field. This method was generated because pub_crate_field is a tail field.

pub(crate) fn with_pub_crate_field_mut<'outer_borrow, ReturnType>(
    &'outer_borrow mut self,
    user: impl for<'this> FnOnce(&'outer_borrow mut &'this i32) -> ReturnType
) -> ReturnType
[src]

Provides a mutable reference to pub_crate_field. This method was generated because pub_crate_field is a tail field. No borrow_pub_crate_field_mut function was generated because Rust’s borrow checker is currently unable to guarantee that such a method would be used safely.

pub fn with<'outer_borrow, ReturnType>(
    &'outer_borrow self,
    user: impl for<'this> FnOnce(BorrowedFields<'outer_borrow, 'this>) -> ReturnType
) -> ReturnType
[src]

This method provides immutable references to all tail and immutably borrowed fields.

pub fn with_mut<'outer_borrow, ReturnType>(
    &'outer_borrow mut self,
    user: impl for<'this> FnOnce(BorrowedMutFields<'outer_borrow, 'this>) -> ReturnType
) -> ReturnType
[src]

This method provides mutable references to all tail fields.

pub fn into_heads(self) -> Heads[src]

This function drops all internally referencing fields and returns only the head fields of this struct.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.