pub fn listen<A>(self, address: A, initial_html: &str) -> io::Result<Listening>
    where
        A: ToSocketAddrs,
    {
        let working_directory = Arc::new(Mutex::new(self.working_directory));

        // This is a bit of a hack, should probably use real URLs here.
        let (remote_custom_css, local_custom_css): (Vec<String>, Vec<String>) = self.styles
            .css
            .into_iter()
            .partition(|css| !css.starts_with("file://"));

        let local_custom_css = local_custom_css
            .into_iter()
            .flat_map(|file_uri| File::open(file_uri.trim_left_matches("file://")).ok())
            .map(|mut file| {
                let mut css = String::new();
                file.read_to_string(&mut css).unwrap();
                css
            })
            .collect();

        let handler = create_handler(MarkdownPreview {
            template_data: TemplateData {
                websocket_port: self.websocket_port,
                initial_html: initial_html.to_owned(),
                highlight_theme: self.styles.highlight_theme,
                remote_custom_css,
                local_custom_css,
            },
            working_directory: working_directory.clone(),
        });

        let listening = Listening {
            working_directory: working_directory,
            listening: Iron::new(handler)
                .http(address)
                .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?,
        };

        Ok(listening)
    }
/// Starts the server.
///
/// Once a connection is received, the client will initiate WebSocket connections on
/// `websocket_port`. If `initial_markdown` is present, it will be displayed on the first
/// connection.
Starts the server.
Once a connection is received, the client will initiate WebSocket connections on
`websocket_port`. If `initial_markdown` is present, it will be displayed on the first
connection.
Starts the server . Once a connection is received the client will initiate WebSocket connections on ` websocket_port ` . If ` initial_markdown ` is present it will be displayed on the first connection .
pub fn listen<A>(self, address: A, initial_html: &str) -> io::Result<Listening>
    where
        A: ToSocketAddrs,
    {
        let working_directory = Arc::new(Mutex::new(self.working_directory));
        // This is a bit of a hack, should probably use real URLs here.
        let (remote_custom_css, local_custom_css): (Vec<String>, Vec<String>) = self.styles
            .css
            .into_iter()
            .partition(|css| !css.starts_with("file://"));
        let local_custom_css = local_custom_css
            .into_iter()
            .flat_map(|file_uri| File::open(file_uri.trim_left_matches("file://")).ok())
            .map(|mut file| {
                let mut css = String::new();
                file.read_to_string(&mut css).unwrap();
                css
            })
            .collect();
        let handler = create_handler(MarkdownPreview {
            template_data: TemplateData {
                websocket_port: self.websocket_port,
                initial_html: initial_html.to_owned(),
                highlight_theme: self.styles.highlight_theme,
                remote_custom_css,
                local_custom_css,
            },
            working_directory: working_directory.clone(),
        });
        let listening = Listening {
            working_directory: working_directory,
            listening: Iron::new(handler)
                .http(address)
                .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?,
        };
        Ok(listening)
    }
pub fn listen < A > ( self , address : A , initial_html : & str ) -> io :: Result < Listening > where A : ToSocketAddrs , { let working_directory = Arc :: new ( Mutex :: new ( self . working_directory ) ) ; // This is a bit of a hack, should probably use real URLs here. let ( remote_custom_css , local_custom_css ) : ( Vec < String > , Vec < String > ) = self . styles . css . into_iter ( ) . partition ( | css | ! css . starts_with ( " " ) ) ; let local_custom_css = local_custom_css . into_iter ( ) . flat_map ( | file_uri | File :: open ( file_uri . trim_left_matches ( " " ) ) . ok ( ) ) . map ( | mut file | { let mut css = String :: new ( ) ; file . read_to_string ( & mut css ) . unwrap ( ) ; css } ) . collect ( ) ; let handler = create_handler ( MarkdownPreview { template_data : TemplateData { websocket_port : self . websocket_port , initial_html : initial_html . to_owned ( ) , highlight_theme : self . styles . highlight_theme , remote_custom_css , local_custom_css , } , working_directory : working_directory . clone ( ) , } ) ; let listening = Listening { working_directory : working_directory , listening : Iron :: new ( handler ) . http ( address ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: Other , e ) ) ? , } ; Ok ( listening ) }
Starts the server.
Starts the server .
self
address
A
initial_html
&str
self
address
A
initial_html
&str