| use std::marker::PhantomData; |
|
|
| use anyhow::Result; |
|
|
| use crate::{ReadRef, TraitRef, VcValueTrait, VcValueType, backend::TypedCellContent}; |
|
|
| |
| |
| |
| |
| |
| pub trait VcCast: private::Sealed { |
| type Output; |
|
|
| fn cast(content: TypedCellContent) -> Result<Self::Output>; |
| } |
|
|
| |
| pub struct VcValueTypeCast<T> { |
| _phantom: PhantomData<T>, |
| } |
|
|
| impl<T> VcCast for VcValueTypeCast<T> |
| where |
| T: VcValueType, |
| { |
| type Output = ReadRef<T>; |
|
|
| fn cast(content: TypedCellContent) -> Result<Self::Output> { |
| content.cast() |
| } |
| } |
|
|
| |
| pub struct VcValueTraitCast<T> |
| where |
| T: ?Sized, |
| { |
| _phantom: PhantomData<T>, |
| } |
|
|
| impl<T> VcCast for VcValueTraitCast<T> |
| where |
| T: VcValueTrait + ?Sized, |
| { |
| type Output = TraitRef<T>; |
|
|
| fn cast(content: TypedCellContent) -> Result<Self::Output> { |
| |
| |
| content.cast_trait::<T>() |
| } |
| } |
|
|
| |
| |
| mod private { |
| use super::{VcValueTraitCast, VcValueTypeCast}; |
| use crate::{VcValueTrait, VcValueType}; |
|
|
| pub trait Sealed {} |
| impl<T> Sealed for VcValueTypeCast<T> where T: VcValueType {} |
| impl<T> Sealed for VcValueTraitCast<T> where T: VcValueTrait + ?Sized {} |
| } |
|
|