@@ -796,7 +796,7 @@ pub trait Provider {
796796 /// impl Provider for SomeConcreteType {
797797 /// fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
798798 /// demand.provide_ref::<str>(&self.field)
799- /// .provide_value::<i32>(|| self.num_field);
799+ /// .provide_value::<i32>(self.num_field);
800800 /// }
801801 /// }
802802 /// ```
@@ -881,36 +881,64 @@ impl<'a> Demand<'a> {
881881 ///
882882 /// # Examples
883883 ///
884+ /// Provides an `u8`.
885+ ///
886+ /// ```rust
887+ /// #![feature(provide_any)]
888+ ///
889+ /// use std::any::{Provider, Demand};
890+ /// # struct SomeConcreteType { field: u8 }
891+ ///
892+ /// impl Provider for SomeConcreteType {
893+ /// fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
894+ /// demand.provide_value::<u8>(self.field);
895+ /// }
896+ /// }
897+ /// ```
898+ #[ unstable( feature = "provide_any" , issue = "96024" ) ]
899+ pub fn provide_value < T > ( & mut self , value : T ) -> & mut Self
900+ where
901+ T : ' static ,
902+ {
903+ self . provide :: < tags:: Value < T > > ( value)
904+ }
905+
906+ /// Provide a value or other type with only static lifetimes computed using a closure.
907+ ///
908+ /// # Examples
909+ ///
884910 /// Provides a `String` by cloning.
885911 ///
886912 /// ```rust
887- /// # #![feature(provide_any)]
913+ /// #![feature(provide_any)]
914+ ///
888915 /// use std::any::{Provider, Demand};
889916 /// # struct SomeConcreteType { field: String }
890917 ///
891918 /// impl Provider for SomeConcreteType {
892919 /// fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
893- /// demand.provide_value ::<String>(|| self.field.clone());
920+ /// demand.provide_value_with ::<String>(|| self.field.clone());
894921 /// }
895922 /// }
896923 /// ```
897924 #[ unstable( feature = "provide_any" , issue = "96024" ) ]
898- pub fn provide_value < T > ( & mut self , fulfil : impl FnOnce ( ) -> T ) -> & mut Self
925+ pub fn provide_value_with < T > ( & mut self , fulfil : impl FnOnce ( ) -> T ) -> & mut Self
899926 where
900927 T : ' static ,
901928 {
902929 self . provide_with :: < tags:: Value < T > > ( fulfil)
903930 }
904931
905- /// Provide a reference, note that the referee type must be bounded by `'static`,
932+ /// Provide a reference. The referee type must be bounded by `'static`,
906933 /// but may be unsized.
907934 ///
908935 /// # Examples
909936 ///
910937 /// Provides a reference to a field as a `&str`.
911938 ///
912939 /// ```rust
913- /// # #![feature(provide_any)]
940+ /// #![feature(provide_any)]
941+ ///
914942 /// use std::any::{Provider, Demand};
915943 /// # struct SomeConcreteType { field: String }
916944 ///
@@ -925,6 +953,40 @@ impl<'a> Demand<'a> {
925953 self . provide :: < tags:: Ref < tags:: MaybeSizedValue < T > > > ( value)
926954 }
927955
956+ /// Provide a reference computed using a closure. The referee type
957+ /// must be bounded by `'static`, but may be unsized.
958+ ///
959+ /// # Examples
960+ ///
961+ /// Provides a reference to a field as a `&str`.
962+ ///
963+ /// ```rust
964+ /// #![feature(provide_any)]
965+ ///
966+ /// use std::any::{Provider, Demand};
967+ /// # struct SomeConcreteType { business: String, party: String }
968+ /// # fn today_is_a_weekday() -> bool { true }
969+ ///
970+ /// impl Provider for SomeConcreteType {
971+ /// fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
972+ /// demand.provide_ref_with::<str>(|| {
973+ /// if today_is_a_weekday() {
974+ /// &self.business
975+ /// } else {
976+ /// &self.party
977+ /// }
978+ /// });
979+ /// }
980+ /// }
981+ /// ```
982+ #[ unstable( feature = "provide_any" , issue = "96024" ) ]
983+ pub fn provide_ref_with < T : ?Sized + ' static > (
984+ & mut self ,
985+ fulfil : impl FnOnce ( ) -> & ' a T ,
986+ ) -> & mut Self {
987+ self . provide_with :: < tags:: Ref < tags:: MaybeSizedValue < T > > > ( fulfil)
988+ }
989+
928990 /// Provide a value with the given `Type` tag.
929991 fn provide < I > ( & mut self , value : I :: Reified ) -> & mut Self
930992 where
0 commit comments