Struct AtomicAVal

Source
pub struct AtomicAVal(/* private fields */);
Expand description

WLambda:

!atom = std:sync:atom:new 10;
!channel = std:sync:mpsc:new[];
!thrd = std:spawn_thread $q{
    !val = main.read;
    main.write $[1,$[0,1],3];

    main.read_at 0;
    main.write_at $[1, 0] 320;
    q.send $["done", 10];

} ${ main = atom, q = channel };

!item = queue.pop[];
.item = queue.pop_timeout 1000;

Wraps an AVal like this: Arc<RwLock>. An AtomicAVal is a thread safe container for VVal data structures. It’s used by WLambda functions like std:sync:atom:new, std:sync:atom:read or std:sync:atom:write.

These containers are shared between the threads by passing them to the threads at std:thread:spawn.

Implementations§

Source§

impl AtomicAVal

Source

pub fn new() -> Self

Creates a new empty instance, containing AVal::None.

Source

pub fn write(&self, vv: &VVal) -> VVal

Locks and stores the VVal.

Source

pub fn swap(&self, vv: &VVal) -> VVal

Locks and stores the VVal.

Source

pub fn read(&self) -> VVal

Locks and reads the AVal and converts it to a VVal.

Source

pub fn store_at(&self, _keypath: &VVal, vv: &VVal)

Locks and stores the VVal at the given key path.

Source

pub fn read_at(&self, _keypath: &VVal) -> VVal

Locks and reads the AVal at the given key path.

Trait Implementations§

Source§

impl Clone for AtomicAVal

Source§

fn clone(&self) -> AtomicAVal

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 AtomicAVal

Source§

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

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

impl Default for AtomicAVal

Source§

fn default() -> Self

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

impl VValUserData for AtomicAVal

Source§

fn as_any(&mut self) -> &mut dyn Any

This should be implemented simply by returning a mutable reference to the concrete type self. It allows you to access your data structure from inside a function yourself. Read more
Source§

fn call_method(&self, key: &str, env: &mut Env) -> Result<VVal, StackAction>

This method is called, when the user data object is used in a method call directly. Use this to implement convenient APIs for the user of the user data object. To quickly get the arguments you may use env.argv_ref().
Source§

fn clone_ud(&self) -> Box<dyn VValUserData>

Should clone your user data instance. Whether you are doing a deep clone or a shallow clone or something else is up to you.
Source§

fn s(&self) -> String

This method should return a human readable syntax representation of your VValUserData.
Source§

fn s_raw(&self) -> String

If your data has a plain string representation, you can return the string directly from here.
Source§

fn i(&self) -> i64

Returns the i64 representation of your data.
Source§

fn byte(&self) -> u8

Returns the byte representation of your data.
Source§

fn c(&self) -> char

Returns the char representation of your data.
Source§

fn f(&self) -> f64

Returns the f64 representation of your data.
Source§

fn b(&self) -> bool

Returns the boolean representation of your data. Can for instance be used to check if your data is valid or something.
Source§

fn eqv(&self, _other: &Box<dyn VValUserData>) -> bool

Allows you to specify how two instances of your data should be compared for equivalentness.
Source§

fn set_key(&self, _key: &VVal, _val: VVal) -> Result<(), StackAction>

Makes your user data act like a map. This can be useful for implementing your own registries or data structures. Implement this method for setting a key to a value.
Source§

fn delete_key(&self, _key: &VVal) -> Result<VVal, StackAction>

This method is called when the user wants to remove a key. Typically called when std:delete from the prelude is called.
Source§

fn get_key(&self, _key: &str) -> Option<VVal>

This method returns some value that your user data associates with the given key.
Source§

fn call(&self, _env: &mut Env) -> Result<VVal, StackAction>

This method is called when the user data is called. To quickly get the arguments you may use env.argv_ref().
Source§

fn as_thread_safe_usr(&mut self) -> Option<Box<dyn ThreadSafeUsr>>

This function is called when you try to pass a user data value between threads via the Atoms provided by the thread implementation of WLambda. Read more

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.