Macro hotdrink_rs::ret[][src]

macro_rules! ret {
    ($($e:expr),*) => { ... };
}

Turns a list of inputs into a successful MethodResult. This can be used defining methods in components with component!. To make returning the possible values of a sum type used in a Component easier, it will automatically call Into::into on each argument.

Examples

ret! can be used with normal values like i32.

let result: MethodResult<i32> = ret![3, 5];
assert_eq!(result, Ok(vec![3, 5]));

It can also be used with enums.

enum Shape {
    Circle(usize),
    Square(usize, usize),
}
let result: MethodResult<Shape> = ret![Shape::Circle(3), Shape::Square(4, 5)];
assert_eq!(result, Ok(vec![Shape::Circle(3), Shape::Square(4, 5)]));

Even with wrapper types that implement From::from its variants. These values can then be used directly in ret!, and they will automatically be converted if possible.

enum Value {
    i32(i32),
    f64(f64),
}

// impl From<i32> for Value { ... }

// impl From<f64> for Value { ... }

let result: MethodResult<Value> = ret![3i32, 5.0f64];
assert_eq!(result, Ok(vec![Value::i32(3), Value::f64(5.0)]));