Struct Client

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

HTTP client used to interact with the pCloud API.

Implementations§

Source§

impl Client

Source

pub async fn get_file_checksum( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<FileChecksum>

Retrieves the checksums and metadata for a file on pCloud.

This function calls the checksumfile endpoint and returns a FileChecksum struct containing the MD5, SHA-1, and SHA-256 hashes, as well as basic metadata for the specified file.

§Arguments
  • identifier - A type that can be converted into a FileIdentifier used to identify the file (e.g., by file ID or path).
§Errors

Returns a crate::Error if the request fails or if the file cannot be found.

§Examples
let checksum = client.get_file_checksum("myfolder/myfile.txt").await?;
println!("SHA-1: {}", checksum.sha1);
Source§

impl Client

Source

pub async fn delete_file( &self, identifier: impl Into<FileIdentifier<'_>>, ) -> Result<File>

Deletes a file from pCloud.

This function calls the deletefile endpoint to remove the specified file from the user’s pCloud storage. It returns the metadata of the deleted file upon success.

§Arguments
  • identifier - A type convertible into a FileIdentifier that identifies the file to delete (e.g., by file ID or path).
§Returns

A File struct containing metadata about the deleted file.

§Errors

Returns a crate::Error if the file does not exist or the API request fails.

§Examples
let deleted_file = client.delete_file("myfolder/myfile.txt").await?;
println!("Deleted file ID: {}", deleted_file.file_id);
Source§

impl Client

Source

pub async fn move_file( &self, file: impl Into<FileIdentifier<'_>>, to_folder: impl Into<FolderIdentifier<'_>>, ) -> Result<File>

Moves a file to a different folder on pCloud.

This function calls the renamefile API endpoint to move the specified file to a new folder. The file is identified either by its file ID or by path.

§Arguments
  • file - A value that can be converted into a FileIdentifier (e.g., file ID or path).
  • to_folder - A value that can be converted into a FolderIdentifier representing the destination folder.
§Returns

On success, returns a File struct containing metadata about the moved file.

§Errors

Returns a crate::Error if the file or folder is not found, or if the API request fails.

§Examples
let file = client.move_file(12345678u64, "/new/folder").await?;
println!("Moved file name: {}", file.base.name);
Source§

impl Client

Source

pub async fn rename_file<'a>( &self, identifier: impl Into<FileIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<File>

Renames a file on pCloud.

This function calls the renamefile API endpoint to change the name of a file. The file can be specified by its ID or path, and the new name must be a string.

§Arguments
  • identifier - A value convertible into a FileIdentifier representing the file to rename.
  • name - The new name to assign to the file.
§Returns

On success, returns a File struct containing metadata about the renamed file.

§Errors

Returns a crate::Error if the file doesn’t exist or if the API request fails.

§Examples
let renamed = client.rename_file(12345678u64, "new_name.txt").await?;
println!("Renamed file: {:?}", renamed.base.name);
Source§

impl Client

Source

pub async fn upload_files( &self, parent: impl Into<FolderIdentifier<'_>>, files: MultiFileUpload, ) -> Result<Vec<File>>

Uploads multiple files to a specified folder on pCloud.

This method uses multipart form submission to upload several files in a single request.

§Arguments
  • parent - A value convertible into a FolderIdentifier representing the destination folder.
  • files - A MultiFileUpload builder containing the files to upload.
§Returns

On success, returns a list of File metadata for each uploaded file.

§Errors

Returns a crate::Error if the upload fails due to network issues, invalid input, or server-side errors.

§Examples
use bytes::Bytes;
use futures_util::stream;

let data = vec![Ok(Bytes::from_static(b"hello world"))];
let stream = stream::iter(data);

let upload = pcloud::file::upload::MultiFileUpload::default()
    .with_stream_entry("hello.txt", 11, stream);

let uploaded = client.upload_files("/my-folder", upload).await?;
println!("Uploaded {} file(s)", uploaded.len());
Source§

impl Client

Source

pub async fn create_folder<'a>( &self, parent: impl Into<FolderIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<Folder>

Creates a new folder inside the specified parent folder on pCloud.

This function calls the createfolder API endpoint and will return an error if a folder with the same name already exists in the target location.

§Arguments
  • parent - A value convertible into a FolderIdentifier representing the parent folder.
  • name - The name of the folder to create.
§Returns

On success, returns a Folder representing the newly created folder.

§Errors

Returns a crate::Error if the folder already exists or the request fails.

§Examples
let folder = client.create_folder(0, "new-folder").await?;
println!("Created folder: {}", folder.base.name);
Source§

impl Client

Source

pub async fn create_folder_if_not_exists<'a>( &self, parent: impl Into<FolderIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<Folder>

Creates a new folder if it does not already exist in the specified location.

This function calls the createfolderifnotexists API endpoint, which ensures the operation is idempotent: if a folder with the given name exists, it will be returned. Otherwise, a new folder is created.

§Arguments
  • parent - A value convertible into a FolderIdentifier representing the parent folder.
  • name - The name of the folder to create or return if it exists.
§Returns

A Folder representing the existing or newly created folder.

§Errors

Returns a crate::Error if the request fails for any reason other than the folder already existing.

§Examples
let folder = client.create_folder_if_not_exists(0, "my-folder").await?;
println!("Folder ID: {}", folder.folder_id);
Source§

impl Client

Source

pub async fn delete_folder<'a>( &self, identifier: impl Into<FolderIdentifier<'a>>, ) -> Result<Folder>

Deletes an empty folder from pCloud.

This function calls the deletefolder API endpoint. It will fail if the folder is not empty or cannot be deleted.

§Arguments
  • identifier - A value that can be converted into a FolderIdentifier (e.g., folder ID or path).
§Returns

On success, returns the metadata of the deleted folder as a Folder object.

§Errors

Returns a crate::Error if the folder does not exist, is not empty, or the API call fails.

§Examples
let folder = client.delete_folder("/my/empty/folder").await?;
println!("Deleted folder: {}", folder.base.name);
Source§

impl Client

Source

pub async fn delete_folder_recursive<'a>( &self, identifier: impl Into<FolderIdentifier<'a>>, ) -> Result<RecursivePayload>

Recursively deletes a folder and all of its contents from pCloud.

This function calls the deletefolderrecursive API endpoint and removes the folder and everything inside it (including subfolders and files).

§Arguments
  • identifier - A value that can be converted into a FolderIdentifier (e.g., folder ID or path).
§Returns

A RecursivePayload struct containing statistics about how many files and folders were deleted.

§Errors

Returns a crate::Error if the folder does not exist or the API call fails.

§Examples
let result = client.delete_folder_recursive(12345u64).await?;
println!(
    "Deleted {} files and {} folders",
    result.deleted_files,
    result.deleted_folders
);
Source§

impl Client

Source

pub async fn list_folder( &self, identifier: impl Into<FolderIdentifier<'_>>, ) -> Result<Folder>

Lists the contents of a folder on pCloud.

This is a convenience method that calls crate::Client::list_folder_with_options with default options. It will list the folder’s immediate contents, including files and subfolders.

§Arguments
  • identifier - A value convertible into a FolderIdentifier (e.g., path or folder ID).
§Returns

A Folder struct containing metadata and child entries.

§Errors

Returns a crate::Error if the folder cannot be listed.

§Examples
let folder = client.list_folder("/Documents").await?;
println!("Folder has {:?} entries", folder.contents.map(|res| res.len()).unwrap_or(0));
Source

pub async fn list_folder_with_options( &self, identifier: impl Into<FolderIdentifier<'_>>, options: ListFolderOptions, ) -> Result<Folder>

Lists the contents of a folder with custom options.

This method gives fine-grained control over how the folder contents are returned by the listfolder endpoint, such as recursive listing and filtering.

§Arguments
  • identifier - A value convertible into a FolderIdentifier (e.g., path or folder ID).
  • options - A ListFolderOptions struct specifying what to include in the listing.
§Returns

A Folder with metadata and contents matching the provided options.

§Errors

Returns a crate::Error if the folder is inaccessible or the API call fails.

§Examples
use pcloud::folder::list::ListFolderOptions;

let options = ListFolderOptions::default()
    .with_recursive()
    .with_show_deleted();
let folder = client.list_folder_with_options("/Backup", options).await?;
println!("Listed folder: {:?}", folder.base.name);
Source§

impl Client

Source

pub async fn move_folder( &self, folder: impl Into<FolderIdentifier<'_>>, to_folder: impl Into<FolderIdentifier<'_>>, ) -> Result<Folder>

Moves a folder to a new location in pCloud.

This function calls the renamefolder API endpoint and moves the specified folder from its current location to the target folder. Both the source and destination can be specified either by folder ID or path.

§Arguments
  • folder - A value that can be converted into a FolderIdentifier (e.g., folder ID or path).
  • to_folder - The target folder identifier (e.g., folder ID or path) to move the folder into.
§Returns

A Folder struct containing the metadata of the moved folder.

§Errors

Returns a crate::Error if the move operation fails, such as if either folder is not accessible or the API call encounters an issue.

§Examples
let moved_folder = client.move_folder("/OldFolder", "/NewFolder").await?;
println!("Moved folder: {:?}", moved_folder.base.name);
Source§

impl Client

Source

pub async fn rename_folder<'a>( &self, identifier: impl Into<FolderIdentifier<'a>>, name: impl Into<Cow<'a, str>>, ) -> Result<Folder>

Renames an existing folder in pCloud.

This function calls the renamefolder API endpoint to rename the specified folder. The folder is identified either by its folder ID or its path, and the new name is provided as a string.

§Arguments
  • identifier - The identifier for the folder to be renamed, which can be provided either by folder ID or path.
  • name - The new name for the folder.
§Returns

A Folder struct containing the metadata of the renamed folder.

§Errors

Returns a crate::Error if the rename operation fails, for example, if the folder does not exist or the API request encounters an issue.

§Examples
let renamed_folder = client.rename_folder("/OldFolder", "NewFolderName").await?;
println!("Renamed folder: {:?}", renamed_folder.base.name);
Source§

impl Client

Source

pub async fn get_digest(&self) -> Result<Digest>

Generates an authentication digest, valid for 30 seconds.

§Returns

A Digest struct containing the digest itself

§Errors

Returns a crate::Error if the folder cannot be listed.

§Examples
let value = client.get_digest().await?;
println!("{:?}", value);
Source§

impl Client

Source

pub async fn get_token(&self) -> Result<String>

Generate a new token based on the provided credentials

§Returns

A [Digest] struct containing the digest itself

§Errors

Returns a crate::Error if the folder cannot be listed.

§Examples
let value = client.get_digest().await?;
println!("{:?}", value);
Source§

impl Client

Source

pub async fn user_info(&self) -> Result<UserInfo>

Fetches the information about the current user.

§Returns

A UserInfo struct containing the user information.

§Errors

Returns a crate::Error if the folder cannot be listed.

§Examples
let info = client.user_info().await?;
println!("{:?}", info);
Source§

impl Client

Gets an audio link using only the file identifier, without additional parameters.

§Arguments
  • identifier - The identifier of the file.
§Returns

A result containing the StreamingLinkList with the generated audio links.

Gets an audio link using both the file identifier and additional parameters.

§Arguments
  • identifier - The identifier of the file.
  • params - The parameters to customize the audio link (e.g., audio bit rate, force download).
§Returns

A result containing the StreamingLinkList with the generated audio links.

Source§

impl Client

Gets a file link using only the file identifier, without additional parameters.

§Arguments
  • identifier - The identifier of the file.
§Returns

A result containing the StreamingLinkList with the generated file links.

Gets a file link using both the file identifier and additional parameters.

§Arguments
  • identifier - The identifier of the file.
  • params - The parameters to customize the file link (e.g., force download, content type, etc.).
§Returns

A result containing the StreamingLinkList with the generated file links.

Source§

impl Client

Gets a video link using only the file identifier, without additional parameters.

§Arguments
  • identifier - The identifier of the file.
§Returns

A result containing the StreamingLinkList with the generated video links.

Gets a video link using both the file identifier and additional parameters.

§Arguments
  • identifier - The identifier of the file.
  • params - The parameters to customize the video link (e.g., audio bit rate, video bit rate, resolution).
§Returns

A result containing the StreamingLinkList with the generated video links.

Source§

impl Client

Source

pub fn builder() -> ClientBuilder

Creates a new ClientBuilder instance for custom configuration.

Source

pub fn new( base_url: impl Into<Cow<'static, str>>, credentials: Credentials, ) -> Result<Self>

Creates a new Client with the specified base URL and credentials.

§Errors

Returns a reqwest::Error if the inner HTTP client fails to build.

Source

pub fn set_credentials(&mut self, credentials: Credentials)

Update the credentials of the client

Source

pub fn with_credentials(self, credentials: Credentials) -> Self

Take ownership of the client and update the credentials

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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,

Source§

impl<T> MaybeSendSync for T