[][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]

impl Debug for WeldValue[src]

Auto Trait Implementations

impl !RefUnwindSafe for WeldValue

impl !Send for WeldValue

impl !Sync for WeldValue

impl Unpin for WeldValue

impl !UnwindSafe for WeldValue

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.