Age | Commit message (Collapse) | Author |
|
|
|
Make `main.rs` responsible for only the `main()` function and command
line option handling. Move the actual application code to `lib.rs` for
clearer separation of concerns.
|
|
Previously, errors would be returned immediately by the `?`/`try!`s.
Handle errors directly instead of returning them. Otherwise, the stream
listener would terminate, exiting the program, and forcing users to
restart it in order to restore functionality.
|
|
When printing errors to STDERR, ensure we're writing newlines to
separate error messages.
|
|
Using `expect` seems nicer here because it allows us to provide a more
meaningful error message.
|
|
Parse the URL coming in from the TCP stream to check that it's a valid
URL. This allows us to fail early and not try to open strings that are
not URLs. Leverage the "url" crate to do the parsing.
Return a `Box<Error>` from `open_stream()` to enable us to return either
an `io` or a `Url` error in our `Result`.
Remove the `trim_right()` call on `url` since it's now a `Url` type
instead of a `String`, and as a result of parsing to a `Url`, it no
longer has the problematic trailing newline.
|
|
Instead get these from function arguments, which in turn get fed from
the command line arguments passed by the user.
|
|
Remove the magic number and replace it with a named value.
|
|
Provide users with an option to change the default port the program
listens on.
|
|
Instead of checking for the presence of the `-b` option before setting
it, just use an `Option` match since `opt_str` returns an
`Option<String>`.
|
|
This will be used to set the browser to open URLs in.
|
|
Use Getopts to parse command line options. Currently only has a 'help'
option, but this lays the foundation for user-customisable browser and
port values.
|
|
Remove the `match` call from efa7f80d962aa0f55f3addbac1da206538d9242e
and use `unwrap_or_else` instead since we don't need to do anything
extra in the `Ok` case.
|
|
Print all errors to STDERR.
|
|
Use the Mac OS X `open` command to open Opera and pass in the contents
of the TCP stream as an argument, assuming it to be a URL that should
be opened in the browser.
Only dealing with the `open` command for now. Will be extending this to
support user-customisable browsers, so that any GUI browser that can be
opened with `open` can be used.
|
|
The call to write to STDERR returns a `Result`. Wrap it in a `try!` to
handle the result and eliminate the "unused result" compilation
warning.
|
|
We only need the `TcpListener` for what we're doing.
|
|
|
|
Going with TCP as that seems like it will work well. Get rid of our UDP
code.
|
|
Replicate the TcpListener example from the Rust standard library docs.
Using TCP instead of UDP allows us to read directly to a string and read
arbitrary length streams.
Here we just print the stream input to the console.
|
|
Copies the example given at
https://doc.rust-lang.org/std/net/struct.UdpSocket.html to experiment
with receiving and sending data over the socket.
|
|
Rust v1.13.0.
$ cargo init --bin
|