Struct weld::WeldValue[][src]

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]

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);

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);

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 ref conf = WeldConf::new();
let mut module = WeldModule::compile("|x: i32| x + 1", conf).unwrap();

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

let ref mut context = 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);

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 Debug for WeldValue
[src]

Formats the value using the given formatter. Read more

impl Clone for WeldValue
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl !Send for WeldValue

impl !Sync for WeldValue