pub struct LocalServer {
pub uri: String,
pub address: String,
pub response: String,
}Expand description
A local server that can be used to listen for requests.
§Examples
use drive_v3::LocalServer;
let local_server = LocalServer::new();
let received_request = local_server.wait_for_request().expect("failed to listen for requests");
// The local server is now running and waiting for a request,
// run "curl http://localhost:7878/my-request-url" to send one.
assert_eq!(received_request, "http://localhost:7878/my-request-url");Fields§
§uri: StringURI that a website can make requests to in order for them to be received by the server. (default: “http://localhost:7878”)
address: StringAddress where the server listens for requests. (default: “localhost:7878”)
response: StringResponse returned by the server after receiving a request. (default: “request processed!”)
Implementations§
Source§impl LocalServer
impl LocalServer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new LocalServer with default values.
Sourcepub fn at<T: AsRef<str>>(self, address: T, port: usize) -> Self
pub fn at<T: AsRef<str>>(self, address: T, port: usize) -> Self
Sets the address and port values for a LocalServer.
§Examples
use drive_v3::LocalServer;
let local_server = LocalServer::new().at("127.0.0.1", 8080);
assert_eq!(local_server.uri, "http://127.0.0.1:8080");
assert_eq!(local_server.address, "127.0.0.1:8080");Sourcepub fn with_response<T: AsRef<str>>(self, response: T) -> Self
pub fn with_response<T: AsRef<str>>(self, response: T) -> Self
Sets the response that the LocalServer will return after successfully receiving a request.
§Examples
use drive_v3::LocalServer;
let local_server = LocalServer::new().with_response("this is my response");
assert_eq!( local_server.response, String::from("this is my response") )Sourcepub fn wait_for_request(&self) -> Result<String>
pub fn wait_for_request(&self) -> Result<String>
Runs a LocalServer and binds a listener to its address, after receiving
a request the server will close and return the URI of the
received request.
§Examples
use drive_v3::LocalServer;
let local_server = LocalServer::new();
let received_request = local_server.wait_for_request()?;
// The local server is now running and waiting for a request,
// run "curl http://localhost:7878/my-request-url" to send one.
assert_eq!(received_request, "http://localhost:7878/my-request-url");§Errors
- an
IOerror, if the server fails to to bind a TCP listener itsaddressor if the incoming request is invalid. - a
LocalServererror, if theLocalServerfailed to listen for incoming requests.
Trait Implementations§
Source§impl Debug for LocalServer
impl Debug for LocalServer
Source§impl Default for LocalServer
impl Default for LocalServer
impl Eq for LocalServer
Source§impl PartialEq for LocalServer
impl PartialEq for LocalServer
Source§fn eq(&self, other: &LocalServer) -> bool
fn eq(&self, other: &LocalServer) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for LocalServer
Auto Trait Implementations§
impl Freeze for LocalServer
impl RefUnwindSafe for LocalServer
impl Send for LocalServer
impl Sync for LocalServer
impl Unpin for LocalServer
impl UnsafeUnpin for LocalServer
impl UnwindSafe for LocalServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.