@@ -33,8 +33,60 @@ pub struct NtripConfig {
3333 pub use_tls : bool ,
3434}
3535
36+ impl Default for NtripConfig {
37+ /// Builds a default [NtripConfig] ready to connect to [RtcmProvider::Centipede] network.
38+ /// The network does not requires SSL.
39+ fn default ( ) -> Self {
40+ Self :: from_provider ( RtcmProvider :: Centipede )
41+ }
42+ }
43+
44+ impl NtripConfig {
45+ /// Generate a connection URL ("host:port") from the NtripConfig
46+ pub fn to_url ( & self ) -> String {
47+ format ! ( "{}:{}" , self . host, self . port)
48+ }
49+
50+ /// Prepares an [NtripConfig] for one of our predefined [RtcmProvider]s
51+ pub fn from_provider ( network : RtcmProvider ) -> Self {
52+ Self {
53+ host : network. host ( ) . to_string ( ) ,
54+ port : network. port ( ) ,
55+ use_tls : network. uses_tls ( ) ,
56+ }
57+ }
58+
59+ /// Copies and returns [NtripConfig] with updated "host" IP address
60+ pub fn with_host ( & self , address : & str ) -> Self {
61+ let mut s = self . clone ( ) ;
62+ s. host = address. to_string ( ) ;
63+ s
64+ }
65+
66+ /// Copies and returns [NtripConfig] with updated port number
67+ pub fn with_port ( & self , port : u16 ) -> Self {
68+ let mut s = self . clone ( ) ;
69+ s. port = port;
70+ s
71+ }
72+
73+ /// Copies and returns [NtripConfig] with TLS/SSL active
74+ pub fn with_tls ( & self ) -> Self {
75+ let mut s = self . clone ( ) ;
76+ s. use_tls = true ;
77+ s
78+ }
79+
80+ /// Copies and returns [NtripConfig] without TLS/SSL active
81+ pub fn without_tls ( & self ) -> Self {
82+ let mut s = self . clone ( ) ;
83+ s. use_tls = false ;
84+ s
85+ }
86+ }
87+
3688/// Credentials for an NTRIP (RTCM) service
37- #[ derive( Clone , PartialEq , Debug ) ]
89+ #[ derive( Clone , Default , PartialEq , Debug ) ]
3890#[ cfg_attr( feature = "clap" , derive( clap:: Parser ) ) ]
3991pub struct NtripCredentials {
4092 /// Username for the NTRIP service
@@ -49,10 +101,19 @@ pub struct NtripCredentials {
49101 pub pass : String ,
50102}
51103
52- impl NtripConfig {
53- /// Generate a connection URL ("host:port") from the NtripConfig
54- pub fn url ( & self ) -> String {
55- format ! ( "{}:{}" , self . host, self . port)
104+ impl NtripCredentials {
105+ /// Copies and returns updated [NtripCredentials]
106+ pub fn with_username ( & self , username : & str ) -> Self {
107+ let mut s = self . clone ( ) ;
108+ s. user = username. to_string ( ) ;
109+ s
110+ }
111+
112+ /// Copies and returns updated [NtripCredentials]
113+ pub fn with_password ( & self , password : & str ) -> Self {
114+ let mut s = self . clone ( ) ;
115+ s. pass = password. to_string ( ) ;
116+ s
56117 }
57118}
58119
@@ -98,8 +159,8 @@ impl RtcmProvider {
98159 }
99160 }
100161
101- /// Does the provider require TLS / SSL?
102- pub fn use_tls ( & self ) -> bool {
162+ /// Returns true if this [RtcmProvider] requires TLS/ SSL.
163+ pub fn uses_tls ( & self ) -> bool {
103164 match self {
104165 RtcmProvider :: Linz => false ,
105166 RtcmProvider :: Rtk2Go => false ,
@@ -139,11 +200,7 @@ impl FromStr for NtripConfig {
139200 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
140201 // Match on known providers
141202 if let Ok ( provider) = RtcmProvider :: from_str ( s) {
142- return Ok ( NtripConfig {
143- host : provider. host ( ) . to_string ( ) ,
144- port : provider. port ( ) ,
145- use_tls : provider. use_tls ( ) ,
146- } ) ;
203+ return Ok ( NtripConfig :: from_provider ( provider) ) ;
147204 }
148205
149206 // Strip protocol if present
0 commit comments