[][src]Struct weld::WeldValue

pub struct WeldValue { /* fields omitted */ }

A wrapper for data passed into and out of Weld.

Values produced by Weld (i.e., as a return value from WeldModule::run) hold a reference to the context they are allocated in.

Methods

impl WeldValue[src]

pub fn new_from_data(data: Data) -> WeldValue[src]

Creates a new WeldValue with a particular data pointer.

This function is used to wrap data that will be passed into Weld. Data passed into Weld should be in a standard format that Weld understands: this is usually some kind of packed C structure with a particular field layout.

Examples

use weld::{Data, WeldValue};

let vec = vec![1, 2, 3];
let value = WeldValue::new_from_data(vec.as_ptr() as Data);

pub fn data(&self) -> Data[src]

Returns the data pointer of this WeldValue.

Examples

use weld::{Data, WeldValue};

let vec = vec![1, 2, 3];
let value = WeldValue::new_from_data(vec.as_ptr() as Data);

assert_eq!(vec.as_ptr() as Data, value.data() as Data);

pub fn context(&self) -> Option<WeldContext>[src]

Returns the context of this value.

This method will return None if the value does not have a context (e.g., if it was initialized using new_from_data). If it does have a context, the reference count of the context is increased -- the context will thus not be dropped until this reference is dropped.

Examples

Values created using new_from_data return None:

use weld::{Data, WeldValue};

let vec = vec![1, 2, 3];
let value = WeldValue::new_from_data(vec.as_ptr() as Data);

assert!(value.context().is_none());

Values created by Weld return the context that owns the data:

use weld::*;
use std::cell::Cell;

// Wrap in Cell so we can get a raw pointer
let input = Cell::new(1 as i32);

let conf = &WeldConf::new();
let mut module = WeldModule::compile("|x: i32| x + 1", conf).unwrap();

let input_value = &WeldValue::new_from_data(input.as_ptr() as Data);

let context = &mut WeldContext::new(conf).unwrap();
let result = unsafe { module.run(context, input_value).unwrap() };

assert!(result.context().is_some());
assert_eq!(result.context().as_mut().unwrap(), context);

pub fn run_id(&self) -> Option<RunId>[src]

Returns the run ID of this value if it has one.

A WeldValue will only have a run ID if it was returned by a Weld program. That is, a WeldValue that is created using WeldValue::new_from_data will always have a run_id of None.

Trait Implementations

impl Clone for WeldValue[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for WeldValue[src]

Auto Trait Implementations

impl !Send for WeldValue

impl !Sync for WeldValue

Blanket Implementations

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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