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
impl Client
Sourcepub fn new(url: &str) -> Result<Client, Error>
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 aClientconfigured with the parsed URL. On failure, returns anErrorif the URL string is invalid.
Sourcepub async fn execute(
&self,
request: &ExecuteRequest,
) -> Result<ExecuteResponse, Error>
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 anExecuteRequestthat 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 anExecuteResponsecontaining the output, errors, and status from the Rust playground. On failure, returns anError.
§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.
Sourcepub async fn compile(
&self,
request: &CompileRequest,
) -> Result<CompileResponse, Error>
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 aCompileRequestthat includes the code and metadata such as the toolchain edition, crate type, target, and any compiler settings.
§Returns
Result<CompileResponse, Error>- On success, returns aCompileResponsecontaining the compiler output, including success/failure status, messages, and possible warnings or errors. On failure, returns anErrordescribing 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.
Sourcepub async fn format(
&self,
request: &FormatRequest,
) -> Result<FormatResponse, Error>
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 aFormatRequestthat includes the code to be formatted and optional parameters like the edition to use.
§Returns
Result<FormatResponse, Error>- On success, returns aFormatResponsecontaining the formatted code or an error message if the code could not be formatted. On failure, returns anErrorrepresenting 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.
Sourcepub async fn clippy(
&self,
request: &ClippyRequest,
) -> Result<ClippyResponse, Error>
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 aClippyRequestthat includes the code to be analyzed and optional parameters such as edition or crate type.
§Returns
Result<ClippyResponse, Error>- On success, returns aClippyResponsecontaining Clippy’s diagnostic output (warnings, errors, suggestions). On failure, returns anErrordescribing 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.
Sourcepub async fn miri(&self, request: &MiriRequest) -> Result<MiriResponse, Error>
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 aMiriRequestthat includes the code and metadata such as edition, crate type, and other configuration options.
§Returns
Result<MiriResponse, Error>- On success, returns aMiriResponsecontaining the result of the interpretation. On failure, returns anErrordescribing the issue.
§Errors
Returns an error if the request fails, if the response is invalid, or if the Miri service encounters an internal issue.
Sourcepub async fn macro_expansion(
&self,
request: &MacroExpansionRequest,
) -> Result<MacroExpansionResponse, Error>
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 aMacroExpansionRequestthat includes the code and any configuration options like the edition to use.
§Returns
Result<MacroExpansionResponse, Error>- On success, returns aMacroExpansionResponsecontaining the macro-expanded version of the code. On failure, returns anErrordescribing 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.
Sourcepub async fn crates(&self) -> Result<CratesResponse, Error>
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 aCratesResponsecontaining the names and versions of available crates. On failure, returns anErrordescribing the problem.
§Errors
Returns an error if the request fails, if the response cannot be parsed, or if the crates service is unavailable.
Sourcepub async fn versions(&self) -> Result<VersionsResponse, Error>
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 aVersionsResponsecontaining version details. On failure, returns anErrordescribing what went wrong.
§Errors
Returns an error if the request cannot be completed, the response is malformed, or if the versions service is unavailable.
Sourcepub async fn gist_create(
&self,
request: &GistCreateRequest,
) -> Result<GistResponse, Error>
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 aGistCreateRequestthat includes the code to be uploaded as a Gist and any additional metadata like description or visibility.
§Returns
Result<GistResponse, Error>- On success, returns aGistResponsecontaining the Gist ID and URL. On failure, returns anErrordescribing what went wrong.
§Errors
Returns an error if the HTTP request fails, if the response is malformed, or if the Gist service is unavailable.
Sourcepub async fn gist_get(&self, id: String) -> Result<GistResponse, Error>
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- AStringrepresenting the unique identifier of the Gist to retrieve.
§Returns
Result<GistResponse, Error>- On success, returns aGistResponsecontaining the Gist’s code and metadata. On failure, returns anErrordescribing the issue.
§Errors
Returns an error if the HTTP request fails, if the response is invalid, or if the Gist could not be found.