1- use crate :: { OutputStream , Value , core:: StreamData } ;
1+ use crate :: {
2+ OutputStream , Value , core:: StreamData , lang:: dynamic_lola:: type_checker:: PartialStreamValue ,
3+ } ;
24use futures:: StreamExt ;
35use std:: fmt:: Debug ;
46
@@ -23,3 +25,23 @@ pub fn from_typed_stream<T: Into<Value> + StreamData>(
2325) -> OutputStream < Value > {
2426 Box :: pin ( stream. map ( |x| x. into ( ) ) )
2527}
28+
29+ pub fn to_typed_partial_stream < T : TryFrom < Value , Error = ( ) > + Debug > (
30+ stream : OutputStream < Value > ,
31+ ) -> OutputStream < PartialStreamValue < T > > {
32+ Box :: pin ( stream. map ( |x| match x {
33+ Value :: NoVal => PartialStreamValue :: NoVal ,
34+ Value :: Deferred => PartialStreamValue :: Deferred ,
35+ x => PartialStreamValue :: Known ( x. try_into ( ) . expect ( "Type error when casting stream" ) ) ,
36+ } ) )
37+ }
38+
39+ pub fn from_typed_partial_stream < T : Into < Value > + StreamData > (
40+ stream : OutputStream < PartialStreamValue < T > > ,
41+ ) -> OutputStream < Value > {
42+ Box :: pin ( stream. map ( |x| match x {
43+ PartialStreamValue :: NoVal => Value :: NoVal ,
44+ PartialStreamValue :: Deferred => Value :: Deferred ,
45+ PartialStreamValue :: Known ( value) => value. into ( ) ,
46+ } ) )
47+ }
0 commit comments