@@ -153,21 +153,38 @@ pub struct BrowserOptions {
153153impl fmt:: Display for BrowserOptions {
154154 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
155155 f. write_fmt ( format_args ! (
156- "BrowserOptions(supress_output={})" ,
157- self . suppress_output
156+ "BrowserOptions(supress_output={}, target_hint={} )" ,
157+ self . suppress_output, self . target_hint ,
158158 ) )
159159 }
160160}
161161
162162impl std:: default:: Default for BrowserOptions {
163163 fn default ( ) -> Self {
164+ let target_hint = String :: from ( option_env ! ( "WEBBROWSER_WASM_TARGET" ) . unwrap_or ( "_blank" ) ) ;
164165 BrowserOptions {
165166 suppress_output : true ,
166- target_hint : String :: from ( "_blank" ) ,
167+ target_hint,
167168 }
168169 }
169170}
170171
172+ impl BrowserOptions {
173+ pub fn new ( ) -> Self {
174+ Self :: default ( )
175+ }
176+
177+ pub fn with_suppress_output < ' a > ( & ' a mut self , suppress_output : bool ) -> & ' a mut Self {
178+ self . suppress_output = suppress_output;
179+ self
180+ }
181+
182+ pub fn with_target_hint < ' a > ( & ' a mut self , target_hint : & str ) -> & ' a mut Self {
183+ self . target_hint = target_hint. to_owned ( ) ;
184+ self
185+ }
186+ }
187+
171188/// Opens the URL on the default browser of this platform
172189///
173190/// Returns Ok(..) so long as the browser invocation was successful. An Err(..) is returned only if
@@ -217,7 +234,7 @@ pub fn open_browser(browser: Browser, url: &str) -> Result<()> {
217234/// ```no_run
218235/// use webbrowser::{open_browser_with_options, Browser, BrowserOptions};
219236///
220- /// if open_browser_with_options(Browser::Default, "http://github.com", & BrowserOptions { suppress_output: false } ).is_ok() {
237+ /// if open_browser_with_options(Browser::Default, "http://github.com", BrowserOptions::new().with_suppress_output( false) ).is_ok() {
221238/// // ...
222239/// }
223240/// ```
0 commit comments