@@ -32,8 +32,8 @@ use serde::Serialize;
3232use getset:: { CopyGetters , Getters } ;
3333
3434use crate :: mqtt:: packet:: json_bin_encode:: escape_binary_json_string;
35- use crate :: mqtt:: packet:: mqtt_binary:: MqttBinary ;
36- use crate :: mqtt:: packet:: mqtt_string:: MqttString ;
35+ use crate :: mqtt:: packet:: mqtt_binary:: { IntoMqttBinary , MqttBinary } ;
36+ use crate :: mqtt:: packet:: mqtt_string:: { IntoMqttString , MqttString } ;
3737use crate :: mqtt:: packet:: packet_type:: { FixedHeader , PacketType } ;
3838use crate :: mqtt:: packet:: qos:: Qos ;
3939use crate :: mqtt:: packet:: variable_byte_integer:: VariableByteInteger ;
@@ -679,8 +679,11 @@ impl ConnectBuilder {
679679 /// .client_id("device-001")
680680 /// .unwrap();
681681 /// ```
682- pub fn client_id ( mut self , id : impl AsRef < str > ) -> Result < Self , MqttError > {
683- let mqtt_str = MqttString :: new ( id. as_ref ( ) ) ?;
682+ pub fn client_id < T > ( mut self , id : T ) -> Result < Self , MqttError >
683+ where
684+ T : IntoMqttString ,
685+ {
686+ let mqtt_str = id. into_mqtt_string ( ) ?;
684687 self . client_id_buf = Some ( mqtt_str) ;
685688 Ok ( self )
686689 }
@@ -766,15 +769,19 @@ impl ConnectBuilder {
766769 /// .build()
767770 /// .unwrap();
768771 /// ```
769- pub fn will_message (
772+ pub fn will_message < T , B > (
770773 mut self ,
771- topic : impl AsRef < str > ,
772- payload : impl AsRef < [ u8 ] > ,
774+ topic : T ,
775+ payload : B ,
773776 qos : Qos ,
774777 retain : bool ,
775- ) -> Result < Self , MqttError > {
776- let will_topic = MqttString :: new ( topic. as_ref ( ) ) ?;
777- let will_payload = MqttBinary :: new ( payload. as_ref ( ) . to_vec ( ) ) ?;
778+ ) -> Result < Self , MqttError >
779+ where
780+ T : IntoMqttString ,
781+ B : IntoMqttBinary ,
782+ {
783+ let will_topic = topic. into_mqtt_string ( ) ?;
784+ let will_payload = payload. into_mqtt_binary ( ) ?;
778785
779786 self . will_topic_buf = Some ( will_topic) ;
780787 self . will_payload_buf = Some ( will_payload) ;
@@ -815,8 +822,11 @@ impl ConnectBuilder {
815822 /// .build()
816823 /// .unwrap();
817824 /// ```
818- pub fn user_name ( mut self , name : impl AsRef < str > ) -> Result < Self , MqttError > {
819- let mqtt_str = MqttString :: new ( name. as_ref ( ) ) ?;
825+ pub fn user_name < T > ( mut self , name : T ) -> Result < Self , MqttError >
826+ where
827+ T : IntoMqttString ,
828+ {
829+ let mqtt_str = name. into_mqtt_string ( ) ?;
820830 self . user_name_buf = Some ( mqtt_str) ;
821831
822832 let mut flags = self . connect_flags_buf . unwrap_or ( [ 0b0000_0010 ] ) [ 0 ] ;
@@ -862,8 +872,11 @@ impl ConnectBuilder {
862872 /// .build()
863873 /// .unwrap();
864874 /// ```
865- pub fn password ( mut self , pwd : impl AsRef < [ u8 ] > ) -> Result < Self , MqttError > {
866- let mqtt_bin = MqttBinary :: new ( pwd. as_ref ( ) . to_vec ( ) ) ?;
875+ pub fn password < B > ( mut self , pwd : B ) -> Result < Self , MqttError >
876+ where
877+ B : IntoMqttBinary ,
878+ {
879+ let mqtt_bin = pwd. into_mqtt_binary ( ) ?;
867880 self . password_buf = Some ( mqtt_bin) ;
868881
869882 let mut flags = self . connect_flags_buf . unwrap_or ( [ 0b0000_0010 ] ) [ 0 ] ;
0 commit comments