pub struct Client { /* private fields */ }Expand description
A client used to send requests to Piston.
Implementations
sourceimpl Client
impl Client
sourcepub fn with_url(url: &str) -> Self
pub fn with_url(url: &str) -> Self
Creates a new Client with a url that runs the piston code execution engine.
This makes it possible to interact with a self-hosted instance of piston.
Arguments
url- The url to use as the underlying piston backend.
Returns
Client- The new Client.
Example
let client = piston_rs::Client::with_url("http://localhost:3000");
assert_eq!(client.get_url(), "http://localhost:3000");sourcepub fn with_key(key: &str) -> Self
pub fn with_key(key: &str) -> Self
Creates a new client, with an api key.
Arguments
key- The api key to use.
Returns
Client- The new Client.
Example
let client = piston_rs::Client::with_key("123abc");
assert!(client.get_headers().contains_key("Authorization"));
assert_eq!(client.get_headers().get("Authorization").unwrap(), "123abc");sourcepub fn with_url_and_key(url: &str, key: &str) -> Self
pub fn with_url_and_key(url: &str, key: &str) -> Self
Creates a new Client using a url and an api key.
Arguments
url- The url to use as the underlying piston backend.key- The api key to use.
Returns
Client- The new Client.
Example
let client = piston_rs::Client::with_url_and_key("http://localhost:3000", "123abc");
assert_eq!(client.get_url(), "http://localhost:3000");
assert!(client.get_headers().contains_key("Authorization"));
assert_eq!(client.get_headers().get("Authorization").unwrap(), "123abc");sourcepub fn get_headers(&self) -> HeaderMap
pub fn get_headers(&self) -> HeaderMap
sourcepub async fn fetch_runtimes(&self) -> Result<Vec<Runtime>, Box<dyn Error>>
pub async fn fetch_runtimes(&self) -> Result<Vec<Runtime>, Box<dyn Error>>
Fetches the runtimes from Piston. This is an http request.
Returns
Result<Vec<Runtime>, Box<dyn Error>>- The available runtimes or the error, if any.
Example
let client = piston_rs::Client::new();
if let Ok(runtimes) = client.fetch_runtimes().await {
assert!(!runtimes.is_empty());
} else {
// There was an error contacting Piston.
}sourcepub async fn execute(
&self,
executor: &Executor
) -> Result<ExecResponse, Box<dyn Error>>
pub async fn execute(
&self,
executor: &Executor
) -> Result<ExecResponse, Box<dyn Error>>
Executes code using a given executor. This is an http request.
Arguments
executor- The executor to use.
Returns
Result<ExecutorResponse, Box<dyn Error>>- The response from Piston or the error, if any.
Example
let client = piston_rs::Client::new();
let executor = piston_rs::Executor::new()
.set_language("rust")
.set_version("1.50.0")
.add_file(piston_rs::File::default().set_content(
"fn main() { println!(\"42\"); }",
));
if let Ok(response) = client.execute(&executor).await {
assert!(response.compile.is_some());
assert!(response.run.is_ok());
assert!(response.is_ok());
} else {
// There was an error contacting Piston.
}Trait Implementations
sourceimpl Default for Client
impl Default for Client
sourcefn default() -> Self
fn default() -> Self
Creates a new client. Alias for Client::new.
Returns
Client- The new Client.
Example
let client = piston_rs::Client::default();
assert!(client.get_headers().contains_key("Accept"));
assert!(client.get_headers().contains_key("User-Agent"));
assert!(!client.get_headers().contains_key("Authorization"));
assert_eq!(client.get_url(), "https://emkc.org/api/v2/piston".to_string());Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more