script/conversions.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5/// A version of the `Into<T>` trait from the standard library that can be used
6/// to convert between two types that are not defined in the script crate.
7/// This is intended to be used on dict/enum types generated from WebIDL once
8/// those types are moved out of the script crate.
9pub(crate) trait Convert<T> {
10 fn convert(self) -> T;
11}
12
13/// A version of the `TryInto<T>` trait from the standard library that can be used
14/// to convert between two types that are not defined in the script crate.
15/// This is intended to be used on dict/enum types generated from WebIDL once
16/// those types are moved out of the script crate.
17#[cfg(feature = "webgpu")]
18pub(crate) trait TryConvert<T> {
19 type Error;
20
21 fn try_convert(self) -> Result<T, Self::Error>;
22}