ion/conversions/value/into.rs
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6
7use crate::conversions::ToValue;
8use crate::{Context, Value};
9
10pub type BoxedIntoValue = Box<dyn for<'cx> IntoValue<'cx>>;
11
12/// Represents types that can be converted to JavaScript [Values](Value) with ownership.
13/// Primarily used with dynamic dispatch and [`BoxedIntoValue`].
14pub trait IntoValue<'cx> {
15 /// Converts `self` into a [`Value`] and stores it in `value`.
16 fn into_value(self: Box<Self>, cx: &'cx Context, value: &mut Value);
17}
18
19impl<'cx, T: ToValue<'cx>> IntoValue<'cx> for T {
20 fn into_value(self: Box<Self>, cx: &'cx Context, value: &mut Value) {
21 self.to_value(cx, value);
22 }
23}