Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

A client for interacting with the Rust playground API.

Holds the base URL and the reqwest::Client struct for all requests.

Implementations§

Source§

impl Client

Source

pub fn new(url: &str) -> Result<Client, Error>

Creates a new Client instance with the given base URL.

Parses the provided string into a Url. Returns an error if the URL is invalid.

§Arguments
  • url - A string slice representing the base URL of the Rust playground API.
§Returns
  • Result<Client, Error> - On success, returns a Client configured with the parsed URL. On failure, returns an Error if the URL string is invalid.
Source

pub async fn execute( &self, request: &ExecuteRequest, ) -> Result<ExecuteResponse, Error>

Sends a code execution request to the Rust playground and returns the result.

This asynchronous method takes and ExecuteRequest struct containing the code execution parameters, sends it to the appropriate endpoint on the Rust playground via a POST request, and returns the execution result.

§Arguments
  • request - A reference to an ExecuteRequest that includes the code snippet and configuration options such as edition, crate type, and whether to run or compile.
§Returns
  • Result<ExecuteResponse, Error> - On success, returns an ExecuteResponse containing the output, errors, and status from the Rust playground. On failure, returns an Error.
§Errors

This function will return an error if the HTTP request fails, if the response cannot be parsed, or if the playground service is unavailable.

Source

pub async fn compile( &self, request: &CompileRequest, ) -> Result<CompileResponse, Error>

Sends a code compilation request to the Rust playground and returns the result.

This asynchronous method takes a CompileRequest containing the code and compilation parameters, sends it to the Rust playground’s compile endpoint, and returns the compilation result.

§Arguments
  • request - A reference to a CompileRequest that includes the code and metadata such as the toolchain edition, crate type, target, and any compiler settings.
§Returns
  • Result<CompileResponse, Error> - On success, returns a CompileResponse containing the compiler output, including success/failure status, messages, and possible warnings or errors. On failure, returns an Error describing the issue.
§Errors

Returns an error if the HTTP request fails, if the response cannot be parsed correctly, or if the playground service encounters an issue.

Source

pub async fn format( &self, request: &FormatRequest, ) -> Result<FormatResponse, Error>

Sends a code formatting request to the Rust playground and returns the formatted result.

This asynchronous method takes a FormatRequest containing the Rust code and formatting options, sends it to the Rust playground’s format endpoint, and returns the formatted code or any errors.

§Arguments
  • request - A reference to a FormatRequest that includes the code to be formatted and optional parameters like the edition to use.
§Returns
  • Result<FormatResponse, Error> - On success, returns a FormatResponse containing the formatted code or an error message if the code could not be formatted. On failure, returns an Error representing issues like network failure or parsing problems.
§Errors

This function may return an error if the request fails, the response is invalid, or the Rust playground’s formatting service encounters a problem.

Source

pub async fn clippy( &self, request: &ClippyRequest, ) -> Result<ClippyResponse, Error>

Sends a Clippy linting request to the Rust playground and returns the analysis result.

This asynchronous method takes a ClippyRequest containing the Rust code and configuration, sends it to the Rust playground’s Clippy endpoint, and returns any linter warnings, errors, or suggestions provided by Clippy.

§Arguments
  • request - A reference to a ClippyRequest that includes the code to be analyzed and optional parameters such as edition or crate type.
§Returns
  • Result<ClippyResponse, Error> - On success, returns a ClippyResponse containing Clippy’s diagnostic output (warnings, errors, suggestions). On failure, returns an Error describing what went wrong (e.g., network error, bad request, or service issue).
§Errors

Returns an error if the request cannot be completed, the response is invalid, or the Clippy service is unavailable or encounters an internal error.

Source

pub async fn miri(&self, request: &MiriRequest) -> Result<MiriResponse, Error>

Sends a Miri request to the Rust playground and returns the result of interpreting the code.

This asynchronous method takes a MiriRequest containing the Rust code and any interpreter-specific options, sends it to the Rust playground’s Miri endpoint, and returns the result of running the interpreter on the code.

§Arguments
  • request - A reference to a MiriRequest that includes the code and metadata such as edition, crate type, and other configuration options.
§Returns
  • Result<MiriResponse, Error> - On success, returns a MiriResponse containing the result of the interpretation. On failure, returns an Error describing the issue.
§Errors

Returns an error if the request fails, if the response is invalid, or if the Miri service encounters an internal issue.

Source

pub async fn macro_expansion( &self, request: &MacroExpansionRequest, ) -> Result<MacroExpansionResponse, Error>

Sends a macro expansion request to the Rust playground and returns the result.

This asynchronous method takes a MacroExpansionRequest with Rust code containing macros, sends it to the Rust playground’s macro expansion endpoint, and returns the result of the expanded macros.

§Arguments
  • request - A reference to a MacroExpansionRequest that includes the code and any configuration options like the edition to use.
§Returns
  • Result<MacroExpansionResponse, Error> - On success, returns a MacroExpansionResponse containing the macro-expanded version of the code. On failure, returns an Error describing the issue.
§Errors

Returns an error if the HTTP request fails, if the response is invalid, or if the macro expansion service encounters an issue.

Source

pub async fn crates(&self) -> Result<CratesResponse, Error>

Retrieves the list of available crates from the Rust playground.

This asynchronous method sends a GET request to the crates endpoint and returns a list of crates supported by the playground environment.

§Returns
  • Result<CratesResponse, Error> - On success, returns a CratesResponse containing the names and versions of available crates. On failure, returns an Error describing the problem.
§Errors

Returns an error if the request fails, if the response cannot be parsed, or if the crates service is unavailable.

Source

pub async fn versions(&self) -> Result<VersionsResponse, Error>

Retrieves the supported versions and metadata of the Rust playground.

This asynchronous method sends a GET request to the versions endpoint and returns information about supported Rust versions, targets, and environments.

§Returns
  • Result<VersionsResponse, Error> - On success, returns a VersionsResponse containing version details. On failure, returns an Error describing what went wrong.
§Errors

Returns an error if the request cannot be completed, the response is malformed, or if the versions service is unavailable.

Source

pub async fn gist_create( &self, request: &GistCreateRequest, ) -> Result<GistResponse, Error>

Creates a GitHub Gist from the provided Rust playground code.

This asynchronous method sends a GistCreateRequest to the Gist creation endpoint and returns a response containing the Gist URL or error information.

§Arguments
  • request - A reference to a GistCreateRequest that includes the code to be uploaded as a Gist and any additional metadata like description or visibility.
§Returns
  • Result<GistResponse, Error> - On success, returns a GistResponse containing the Gist ID and URL. On failure, returns an Error describing what went wrong.
§Errors

Returns an error if the HTTP request fails, if the response is malformed, or if the Gist service is unavailable.

Source

pub async fn gist_get(&self, id: String) -> Result<GistResponse, Error>

Retrieves an existing GitHub Gist from the Rust playground.

This asynchronous method sends a GET request to the Gist retrieval endpoint using the provided Gist ID and returns the contents of the Gist.

§Arguments
  • id - A String representing the unique identifier of the Gist to retrieve.
§Returns
  • Result<GistResponse, Error> - On success, returns a GistResponse containing the Gist’s code and metadata. On failure, returns an Error describing the issue.
§Errors

Returns an error if the HTTP request fails, if the response is invalid, or if the Gist could not be found.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

Creates a Client instance with the following url https://play.rust-lang.org/

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,