@@ -37,6 +37,7 @@ use crate::mqtt::packet::mqtt_string::MqttString;
3737use crate :: mqtt:: packet:: packet_type:: { FixedHeader , PacketType } ;
3838use crate :: mqtt:: packet:: GenericPacketDisplay ;
3939use crate :: mqtt:: packet:: GenericPacketTrait ;
40+ use core:: convert:: TryInto ;
4041
4142use crate :: mqtt:: packet:: property:: PropertiesToContinuousBuffer ;
4243use crate :: mqtt:: packet:: qos:: Qos ;
@@ -734,8 +735,11 @@ impl ConnectBuilder {
734735 /// .build()
735736 /// .unwrap();
736737 /// ```
737- pub fn client_id ( mut self , id : impl AsRef < str > ) -> Result < Self , MqttError > {
738- let mqtt_str = MqttString :: new ( id. as_ref ( ) ) ?;
738+ pub fn client_id < T > ( mut self , id : T ) -> Result < Self , MqttError >
739+ where
740+ T : TryInto < MqttString , Error = MqttError > ,
741+ {
742+ let mqtt_str = id. try_into ( ) ?;
739743 self . client_id_buf = Some ( mqtt_str) ;
740744 Ok ( self )
741745 }
@@ -814,15 +818,19 @@ impl ConnectBuilder {
814818 /// .build()
815819 /// .unwrap();
816820 /// ```
817- pub fn will_message (
821+ pub fn will_message < T , B > (
818822 mut self ,
819- topic : impl AsRef < str > ,
820- payload : impl AsRef < [ u8 ] > ,
823+ topic : T ,
824+ payload : B ,
821825 qos : Qos ,
822826 retain : bool ,
823- ) -> Result < Self , MqttError > {
824- let will_topic = MqttString :: new ( topic. as_ref ( ) ) ?;
825- let will_payload = MqttBinary :: new ( payload. as_ref ( ) . to_vec ( ) ) ?;
827+ ) -> Result < Self , MqttError >
828+ where
829+ T : TryInto < MqttString , Error = MqttError > ,
830+ B : TryInto < MqttBinary , Error = MqttError > ,
831+ {
832+ let will_topic = topic. try_into ( ) ?;
833+ let will_payload = payload. try_into ( ) ?;
826834
827835 self . will_topic_buf = Some ( will_topic) ;
828836 self . will_payload_buf = Some ( will_payload) ;
@@ -863,8 +871,11 @@ impl ConnectBuilder {
863871 /// .build()
864872 /// .unwrap();
865873 /// ```
866- pub fn user_name ( mut self , name : impl AsRef < str > ) -> Result < Self , MqttError > {
867- let mqtt_str = MqttString :: new ( name. as_ref ( ) ) ?;
874+ pub fn user_name < T > ( mut self , name : T ) -> Result < Self , MqttError >
875+ where
876+ T : TryInto < MqttString , Error = MqttError > ,
877+ {
878+ let mqtt_str = name. try_into ( ) ?;
868879 self . user_name_buf = Some ( mqtt_str) ;
869880
870881 let mut flags = self . connect_flags_buf . unwrap_or ( [ 0b0000_0010 ] ) [ 0 ] ;
@@ -900,8 +911,11 @@ impl ConnectBuilder {
900911 /// .build()
901912 /// .unwrap();
902913 /// ```
903- pub fn password ( mut self , pwd : impl AsRef < [ u8 ] > ) -> Result < Self , MqttError > {
904- let mqtt_bin = MqttBinary :: new ( pwd. as_ref ( ) . to_vec ( ) ) ?;
914+ pub fn password < B > ( mut self , pwd : B ) -> Result < Self , MqttError >
915+ where
916+ B : TryInto < MqttBinary , Error = MqttError > ,
917+ {
918+ let mqtt_bin = pwd. try_into ( ) ?;
905919 self . password_buf = Some ( mqtt_bin) ;
906920
907921 let mut flags = self . connect_flags_buf . unwrap_or ( [ 0b0000_0010 ] ) [ 0 ] ;
0 commit comments