### Get Full Currencies Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves detailed information for all supported currencies. ```rust pub async fn get_full_currencies(&self) -> Result ``` -------------------------------- ### Get Conversion List Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves a list of all conversion records. ```rust pub async fn get_conversion_list(&self) -> Result ``` -------------------------------- ### Creating a Vec from externally allocated memory Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html This example shows how to create a `Vec` using memory allocated via `std::alloc::alloc`. It's crucial to ensure the layout (size and alignment) used for allocation matches what `Vec::from_raw_parts` expects and that the memory is properly managed afterward. This approach is useful when interfacing with C code or other memory management systems. ```rust use std::alloc::{alloc, Layout}; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let mem = alloc(layout).cast::(); if mem.is_null() { return; } mem.write(1_000_000); Vec::from_raw_parts(mem, 1, 16) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### Start Sending a Value to a Sink Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Initiates sending a value to the sink. Must be preceded by a successful poll_ready call. ```rust fn start_send( self: Pin<&mut Vec>, item: T, ) -> Result<(), as Sink>::Error> ``` -------------------------------- ### Get Payout List Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves a list of all payouts associated with the account. ```rust pub async fn get_payout_list(&self) -> Result ``` -------------------------------- ### Get Currencies Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves a list of available currencies supported by the API. ```rust pub async fn get_currencies(&self) -> Result ``` -------------------------------- ### Get Balance Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves the current account balance. Returns a `Result` containing the balance status. ```rust pub async fn get_balance(&self) -> Result ``` -------------------------------- ### JWT Constructor Source: https://docs.rs/nowpayments/latest/nowpayments/jwt/struct.JWT.html Creates a new instance of the JWT struct. No specific setup is required before calling this. ```rust pub fn new() -> Self ``` -------------------------------- ### Get Checked Currencies Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves a list of currencies that have been checked or validated. ```rust pub async fn get_checked_currencies(&self) -> Result ``` -------------------------------- ### Get Estimated Price Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously estimates the price for a payment conversion. Requires the amount, source currency, and destination currency. ```rust pub async fn get_estimated_price(&self, amount: impl Display, from: impl Display, to: impl Display) -> Result ``` -------------------------------- ### Rebuilding a Vec from its parts Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html This example demonstrates how to safely take ownership of a Vec's allocation, modify its contents, and then reconstruct the Vec. It uses `ManuallyDrop` to prevent the original Vec from being dropped and its memory deallocated prematurely. Ensure all invariants are met before calling `Vec::from_raw_parts`. ```rust use std::ptr; use std::mem; let v = vec![1, 2, 3]; // Prevent running `v`'s destructor so we are in complete control // of the allocation. let mut v = mem::ManuallyDrop::new(v); // Pull out the various important pieces of information about `v` let p = v.as_mut_ptr(); let len = v.len(); let cap = v.capacity(); unsafe { // Overwrite memory with 4, 5, 6 for i in 0..len { ptr::write(p.add(i), 4 + i); } // Put everything back together into a Vec let rebuilt = Vec::from_raw_parts(p, len, cap); assert_eq!(rebuilt, [4, 5, 6]); } ``` -------------------------------- ### Get Minimum Payment Amount Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously calculates the minimum payment amount between two currencies. Both `from` and `to` currencies must be displayable types. ```rust pub async fn get_min_payment_amount(&self, from: impl Display, to: impl Display) -> Result ``` -------------------------------- ### Get List of Payments Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves a paginated and sorted list of payments. Requires parameters for limit, page, sorting, ordering, and date range. ```rust pub async fn get_list_of_payments(&self, limit: impl Display, page: impl Display, sort_by: impl Display, order_by: impl Display, date_from: impl Display, date_to: impl Display) -> Result ``` -------------------------------- ### Initializing Vector Elements via NonNull Pointer in Rust Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Uses the nightly-only `as_non_null()` API to get a `NonNull` pointer for initializing vector elements. Requires the `box_vec_non_null` feature and an unsafe block. ```rust #![feature(box_vec_non_null)] // Allocate vector big enough for 4 elements. let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_non_null(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { x_ptr.add(i).write(i as i32); } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` -------------------------------- ### Insert Element and Get Mutable Reference Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Use the nightly-only `insert_mut` to insert an element and get a mutable reference to it. Panics if `index > len`. This operation has O(n) time complexity. ```rust #![feature(push_mut)] let mut vec = vec![1, 3, 5, 9]; let x = vec.insert_mut(3, 6); *x += 1; assert_eq!(vec, [1, 3, 5, 7, 9]); ``` -------------------------------- ### Initialize NPClient Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Use `new` for live API interactions and `new_sandbox` for testing with the sandbox environment. Both require an API key. ```rust pub fn new(api_key: &str) -> Self ``` ```rust pub fn new_sandbox(api_key: &str) -> Self ``` -------------------------------- ### Get Length Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Returns the number of elements currently in the vector. ```APIDOC ## GET /len ### Description Returns the number of elements in the vector, also referred to as its length. ### Method GET ### Endpoint `/len` ### Response #### Success Response (200) - **usize** (integer) - The number of elements in the vector. ### Response Example ```json { "length": 3 } ``` ``` -------------------------------- ### NPClient Initialization Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Provides methods for initializing the NPClient with an API key, including options for sandbox environments. ```APIDOC ## NPClient Initialization ### Description Initializes the NPClient for interacting with the NOWPayments API. ### Methods #### `new(api_key: &str) -> Self` Creates a new NPClient instance with the provided API key for the production environment. #### `new_sandbox(api_key: &str) -> Self` Creates a new NPClient instance with the provided API key for the sandbox environment. ``` -------------------------------- ### Create Payment Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Creates a new payment with the provided `PaymentOpts`. Returns a `Result` containing the created payment details. ```rust pub async fn create_payment(&self, opts: PaymentOpts) -> Result ``` -------------------------------- ### Allocate and Use Memory for Vec Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Shows how to allocate memory using the global allocator and then construct a Vec from it using `Vec::from_parts`. This is useful for integrating with external memory management. ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let Some(mem) = NonNull::new(alloc(layout).cast::()) else { return; }; mem.write(1_000_000); Vec::from_parts(mem, 1, 16) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### PaymentOpts Constructor Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Creates a new instance of PaymentOpts. Requires various details about the payment. ```rust pub fn new( price_amount: u32, price_currency: impl Display, pay_currency: impl Display, ipn_callback_url: impl Display, order_id: impl Display, order_description: impl Display, ) -> Self ``` -------------------------------- ### Set Authentication Credentials Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Use `set_auth` to configure email and password for authentication. This method requires mutable access to the client. ```rust pub fn set_auth(&mut self, email: String, password: String) ``` -------------------------------- ### Get VarULE length of Vec Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Return the length, in bytes, of the corresponding VarULE type for a Vec. ```rust fn encode_var_ule_len(&self) -> usize ``` -------------------------------- ### Create Vec from Allocated Memory with Global Allocator Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Shows how to allocate memory using the Global allocator, write data to it, and then construct a Vec from these parts. This requires careful handling of memory layout and safety. ```rust #![feature(allocator_api, box_vec_non_null)] use std::alloc::{AllocError, Allocator, Global, Layout}; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let mem = match Global.allocate(layout) { Ok(mem) => mem.cast::(), Err(AllocError) => return, }; mem.write(1_000_000); Vec::from_parts_in(mem, 1, 16, Global) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### Get JWT Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Retrieves a JSON Web Token (JWT) associated with the client's authentication. ```rust pub fn get_jwt(&self) ``` -------------------------------- ### Vec::try_with_capacity_in Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Constructs a new, empty Vec with a specified capacity and allocator. This is a nightly-only experimental API. ```APIDOC ## POST /vec/try_with_capacity_in ### Description Constructs a new, empty `Vec` with at least the specified capacity using the provided allocator. The vector will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is zero, the vector will not allocate. ### Method POST ### Endpoint `/vec/try_with_capacity_in` ### Parameters #### Query Parameters - **capacity** (usize) - Required - The minimum capacity for the new vector. - **alloc** (A) - Required - The allocator to use for this vector. ### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) - **Vec** - A new, empty vector with the specified capacity and allocator. #### Error Response (e.g., 400) - **TryReserveError** - Returned if the capacity exceeds `isize::MAX` bytes, or if the allocator reports an allocation failure. ### Response Example ```json { "example": "new_vec_instance" } ``` ``` -------------------------------- ### Implement CloneToUninit for Generic Type T (Nightly) Source: https://docs.rs/nowpayments/latest/nowpayments/response/conversion/struct.SingleConversion.html Nightly-only experimental API for cloning into uninitialized memory. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get Vector Length Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Returns the number of elements currently in the vector. This operation has a time complexity of O(1). ```rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Create Vec with try_with_capacity (Nightly) Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Constructs a new, empty `Vec` with at least the specified capacity. This is a nightly-only experimental API that returns a `Result` to handle potential allocation failures. ```rust #![feature(try_reserve)] use std::vec::TryReserveError; fn main() -> Result<(), TryReserveError> { let mut vec = Vec::try_with_capacity(10)?; // ... use vec ... Ok(()) } ``` -------------------------------- ### Initializing Vector Elements via Raw Pointer in Rust Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Shows how to initialize vector elements by writing directly to the buffer obtained from `as_mut_ptr()`, then setting the vector's length. This requires an unsafe block. ```rust // Allocate vector big enough for 4 elements. let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_mut_ptr(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { *x_ptr.add(i) = i as i32; } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` -------------------------------- ### Get Immutable Slice of Vec Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Obtain an immutable slice representing the entire Vec using `as_slice`. This is equivalent to `&s[..]`. ```rust use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap(); ``` -------------------------------- ### Reconstruct Vec from Raw Parts with Custom Allocator Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Demonstrates reconstructing a Vec from its raw pointer, length, capacity, and allocator. Ensure all safety invariants are met before calling. ```rust #![feature(allocator_api, box_vec_non_null)] use std::alloc::System; use std::ptr::NonNull; use std::mem; let mut v = Vec::with_capacity_in(3, System); v.push(1); v.push(2); v.push(3); // Prevent running `v`'s destructor so we are in complete control // of the allocation. let mut v = mem::ManuallyDrop::new(v); // Pull out the various important pieces of information about `v` let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) }; let len = v.len(); let cap = v.capacity(); let alloc = v.allocator(); unsafe { // Overwrite memory with 4, 5, 6 for i in 0..len { p.add(i).write(4 + i); } // Put everything back together into a Vec let rebuilt = Vec::from_parts_in(p, len, cap, alloc.clone()); assert_eq!(rebuilt, [4, 5, 6]); } ``` -------------------------------- ### Get Mutable Slice of Vec Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Obtain a mutable slice representing the entire Vec using `as_mut_slice`. This is equivalent to `&mut s[..]`. ```rust use std::io::{self, Read}; let mut buffer = vec![0; 3]; io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap(); ``` -------------------------------- ### Vec::from_raw_parts_in Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Creates a Vec directly from a raw pointer, length, capacity, and allocator. This is a nightly-only experimental API and requires careful handling of memory safety. ```APIDOC ## POST /vec/from_raw_parts_in ### Description Creates a `Vec` directly from a pointer, a length, a capacity, and an allocator. This is a nightly-only experimental API. ### Method POST ### Endpoint `/vec/from_raw_parts_in` ### Parameters #### Path Parameters None #### Query Parameters - **ptr** (*mut T) - Required - A raw mutable pointer to the allocated memory. - **length** (usize) - Required - The number of elements currently in the vector. - **capacity** (usize) - Required - The total capacity of the allocated memory. - **alloc** (A) - Required - The allocator used for the memory. ### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) - **Vec** - A `Vec` created from the provided parts. ### Safety Considerations This function is `unsafe` due to the following invariants that are not checked: - `ptr` must be currently allocated via the given allocator `alloc`. - `T` must have the same alignment as the memory pointed to by `ptr` was allocated with. - The size of `T` times `capacity` must match the allocated size for the pointer. - `length` must be less than or equal to `capacity`. - The first `length` elements must be properly initialized. - `capacity` must fit the layout size the pointer was allocated with. - The allocated size in bytes must not exceed `isize::MAX`. Violating these invariants can lead to memory corruption or undefined behavior. ### Request Example ```json { "ptr": "0x...", "length": 3, "capacity": 10, "alloc": "System" } ``` ### Response Example ```json { "example": "rebuilt_vec_instance" } ``` ``` -------------------------------- ### Implement PartialEq for PaymentStatus Source: https://docs.rs/nowpayments/latest/nowpayments/response/payments/struct.PaymentStatus.html Enables equality comparisons between PaymentStatus instances. This allows checking if two payment status records are identical based on their field values. ```rust fn eq(&self, other: &PaymentStatus) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Implement Sync for PaymentOpts Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Indicates that the PaymentOpts struct can be safely shared between threads. ```rust impl Sync for PaymentOpts ``` -------------------------------- ### Get Conversion Status Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves the status of a specific conversion using its ID. Requires the conversion ID as a displayable type. ```rust pub async fn get_conversion_status(&self, conversion_id: impl Display) -> Result ``` -------------------------------- ### Get Payout Status Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves the status of a specific payout using its ID. Requires the payout ID as a displayable type. ```rust pub async fn get_payout_status(&self, payout_id: impl Display) -> Result ``` -------------------------------- ### Decompose Vec into Raw Parts with System Allocator Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Demonstrates decomposing a Vec into its raw pointer, length, capacity, and allocator. The caller assumes responsibility for the memory and must reconstruct the Vec using `from_raw_parts_in`. ```rust #![feature(allocator_api, vec_into_raw_parts)] use std::alloc::System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_raw_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr as *mut u32; Vec::from_raw_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### PartialEq Implementation for Payment Source: https://docs.rs/nowpayments/latest/nowpayments/response/payments/struct.Payment.html Enables comparison of Payment struct instances for equality. The `eq` method tests if two Payment instances are equal, while `ne` tests for inequality. ```rust fn eq(&self, other: &Payment) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Get Payment Status Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously retrieves the status of a specific payment using its ID. Requires the payment ID as a displayable type. ```rust pub async fn get_payment_status(&self, payment_id: impl Display) -> Result ``` -------------------------------- ### Implement PartialEq for AllPayouts Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/struct.AllPayouts.html Enables equality comparison between AllPayouts instances. Used for checking if two payout collections are identical. ```rust fn eq(&self, other: &AllPayouts) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Get JWT Token Source: https://docs.rs/nowpayments/latest/nowpayments/jwt/struct.JWT.html Retrieves the JWT token as a String. Returns a Result which may contain an error if the token is not set or invalid. ```rust pub fn get(&self) -> Result ``` -------------------------------- ### Implement Any Trait Source: https://docs.rs/nowpayments/latest/nowpayments/response/currencies/struct.Currencies.html Provides runtime type information for types that are 'static. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get Vec Capacity Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Returns the total number of elements the vector can hold without reallocating. For zero-sized elements, capacity is usize::MAX. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` ```rust #[derive(Clone)] struct ZeroSized; fn main() { assert_eq!(std::mem::size_of::(), 0); let v = vec![ZeroSized; 0]; assert_eq!(v.capacity(), usize::MAX); } ``` -------------------------------- ### Implement Send for PaymentOpts Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Indicates that the PaymentOpts struct can be safely sent to another thread. ```rust impl Send for PaymentOpts ``` -------------------------------- ### Get Raw Pointer to Vec Buffer Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Retrieve a raw pointer to the vector's buffer using `as_ptr`. Ensure the vector outlives the pointer and avoid modifying the vector while the pointer is in use to prevent invalidation. ```rust let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3]); assert!(vec.capacity() >= 10); let slice = vec.into_boxed_slice(); assert_eq!(slice.into_vec().capacity(), 3); ``` -------------------------------- ### JWT Struct and Methods Source: https://docs.rs/nowpayments/latest/nowpayments/jwt/struct.JWT.html Provides details on the JWT struct, its constructor, and methods for managing JWT tokens. ```APIDOC ## JWT Struct ### Description Represents a JSON Web Token (JWT) for authentication or information exchange. ### Methods #### `pub fn new() -> Self` Creates a new instance of the JWT struct. #### `pub fn is_expired(&self) -> bool` Checks if the JWT has expired. #### `pub fn get(&self) -> Result` Retrieves the JWT as a String, returning a Result. #### `pub fn set(&mut self, token: String)` Sets or updates the JWT with a new token string. ``` -------------------------------- ### Implement Default for AllPayouts Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/struct.AllPayouts.html Provides a default value for AllPayouts, typically an empty collection of payouts. ```rust fn default() -> AllPayouts ``` -------------------------------- ### Split Vector at Index Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Splits the vector into two at the specified index. Returns a new vector containing elements from the index to the end. The original vector retains elements from the start up to the index. Panics if the index is out of bounds. ```rust let mut v = vec![1, 2, 3, 4, 5]; let v2 = v.split_off(3); assert_eq!(v, &[1, 2, 3]); assert_eq!(v2, &[4, 5]); ``` -------------------------------- ### Get Mutable Reference to Last Element Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html This is a nightly-only experimental API. Returns a mutable reference to the last element if the vector is not empty, otherwise `None`. The reference is wrapped in `PeekMut` which ensures the element is dropped if `PeekMut` is dropped. ```rust #![feature(vec_peek_mut)] let mut vec = Vec::new(); assert!(vec.peek_mut().is_none()); vec.push(1); vec.push(5); vec.push(2); assert_eq!(vec.last(), Some(&2)); if let Some(mut val) = vec.peek_mut() { *val = 0; } assert_eq!(vec.last(), Some(&0)); ``` -------------------------------- ### Clone Implementation for FullCurrencies Source: https://docs.rs/nowpayments/latest/nowpayments/response/currencies/struct.FullCurrencies.html Provides methods to duplicate FullCurrencies values. Use `clone` for a simple copy and `clone_from` for in-place assignment. ```rust fn clone(&self) -> FullCurrencies ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Vec::from_parts_in Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Creates a Vec directly from a NonNull pointer, length, capacity, and allocator. This is a nightly-only experimental API. ```APIDOC ## POST /vec/from_parts_in ### Description Creates a `Vec` directly from a `NonNull` pointer, a length, a capacity, and an allocator. This is a nightly-only experimental API. ### Method POST ### Endpoint `/vec/from_parts_in` ### Parameters #### Query Parameters - **ptr** (NonNull) - Required - A non-null pointer to the allocated memory. - **length** (usize) - Required - The number of elements currently in the vector. - **capacity** (usize) - Required - The total capacity of the allocated memory. - **alloc** (A) - Required - The allocator used for the memory. ### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) - **Vec** - A `Vec` created from the provided parts. ### Response Example ```json { "example": "rebuilt_vec_instance_from_nonnull" } ``` ``` -------------------------------- ### Append element and return mutable reference Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Use `push_mut` to append an element and get a mutable reference to the newly added element. This is a nightly-only API. It may panic if the new capacity exceeds `isize::MAX` bytes. ```rust #![feature(push_mut)] let mut vec = vec![1, 2]; let last = vec.push_mut(3); assert_eq!(*last, 3); assert_eq!(vec, [1, 2, 3]); let last = vec.push_mut(3); *last += 1; assert_eq!(vec, [1, 2, 3, 4]); ``` -------------------------------- ### Implement Any for T Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Provides dynamic type information for any type T. ```rust impl Any for T where T: 'static + ?Sized, ``` -------------------------------- ### Implement PartialEq for AllConversions Source: https://docs.rs/nowpayments/latest/nowpayments/response/conversion/struct.AllConversions.html Enables equality comparison between AllConversions instances. ```rust fn eq(&self, other: &AllConversions) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### pub fn push(&mut self, value: T) Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Appends an element to the back of a collection. This operation takes amortized O(1) time. ```APIDOC ## pub fn push(&mut self, value: T) ### Description Appends an element to the back of a collection. ### Method `&mut self` ### Parameters - `value`: The element of type `T` to append to the vector. ### Panics Panics if the new capacity exceeds `isize::MAX` _bytes_. ### Request Example ```rust let mut vec = vec![1, 2]; vec.push(3); assert_eq!(vec, [1, 2, 3]); ``` ### Time complexity Takes amortized _O_(1) time. If the vector’s length would exceed its capacity after the push, _O_(_capacity_) time is taken to copy the vector’s elements to a larger allocation. This expensive operation is offset by the _capacity_ _O_(1) insertions it allows. ### Response This method modifies the vector in place and does not return a value. ``` -------------------------------- ### NPClient Authentication Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Methods for setting authentication credentials and performing authentication. ```APIDOC ## NPClient Authentication ### Description Handles authentication for the NPClient. ### Methods #### `set_auth(&mut self, email: String, password: String)` Sets the email and password for authentication. #### `authenticate(&mut self) -> Result<()>` Asynchronously authenticates the client. Returns `Ok(())` on success or an error. ``` -------------------------------- ### try_into Method Source: https://docs.rs/nowpayments/latest/nowpayments/response/currencies/struct.SingleCurrency.html Provides the `try_into` method for performing fallible conversions. ```APIDOC ## fn try_into(self) -> Result>::Error> ### Description Performs the conversion. ### Source (Source code location not specified) ``` -------------------------------- ### Implement Clone for AllPayouts Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/struct.AllPayouts.html Provides the ability to clone an AllPayouts instance. This allows for creating a duplicate of the payout data. ```rust fn clone(&self) -> AllPayouts ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Define PaymentOpts Struct Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Defines the structure for payment options. It contains private fields. ```rust pub struct PaymentOpts { /* private fields */ } ``` -------------------------------- ### Vec Partial Ordering (PartialOrd) Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Implements partial lexicographical ordering for Vec against Vec where T implements PartialOrd. ```APIDOC ## impl PartialOrd> for Vec ### Description Implements partial lexicographical ordering for vectors. ### Methods #### fn partial_cmp(&self, other: &Vec) -> Option Compares `self` with `other` and returns an `Option` if comparison is possible. #### fn lt(&self, other: &Rhs) -> bool Tests if `self` is less than `other`. #### fn le(&self, other: &Rhs) -> bool Tests if `self` is less than or equal to `other`. #### fn gt(&self, other: &Rhs) -> bool Tests if `self` is greater than `other`. #### fn ge(&self, other: &Rhs) -> bool Tests if `self` is greater than or equal to `other`. ``` -------------------------------- ### Authenticate NPClient Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Asynchronously authenticates the client. This operation returns a `Result` which can be `Ok(())` on success or an error. ```rust pub async fn authenticate(&mut self) -> Result<()> ``` -------------------------------- ### Construct a Vec with capacity and a specific allocator Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Use `Vec::with_capacity_in` to create an empty vector with a specified minimum capacity and allocator. This is a nightly-only experimental API. ```rust #![feature(allocator_api)] use std::alloc::System; let mut vec = Vec::with_capacity_in(10, System); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); // These are all done without reallocating... for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); // ...but this may make the vector reallocate vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); // A vector of a zero-sized type will always over-allocate, since no // allocation is necessary let vec_units = Vec::<(), System>::with_capacity_in(10, System); assert_eq!(vec_units.capacity(), usize::MAX); ``` -------------------------------- ### Split Vec into two parts Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Demonstrates splitting a vector into two parts at a specified index. The original vector retains elements up to the split point, and the second vector contains the remaining elements. ```rust let mut vec = vec!['a', 'b', 'c']; let vec2 = vec.split_off(1); assert_eq!(vec, ['a']); assert_eq!(vec2, ['b', 'c']); ``` -------------------------------- ### Implement Unpin for PaymentOpts Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Indicates that the PaymentOpts struct does not require special handling for pinning. ```rust impl Unpin for PaymentOpts ``` -------------------------------- ### Construct Vec with Capacity and Allocator Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Constructs a new, empty `Vec` with a specified minimum capacity using a given allocator. The vector may allocate more space than requested. If capacity is zero, no allocation occurs. ```rust #![feature(allocator_api)] use std::alloc::System; use std::ptr; use std::mem; let mut v = Vec::with_capacity_in(3, System); v.push(1); v.push(2); v.push(3); // Prevent running `v`'s destructor so we are in complete control // of the allocation. let mut v = mem::ManuallyDrop::new(v); // Pull out the various important pieces of information about `v` let p = v.as_mut_ptr(); let len = v.len(); let cap = v.capacity(); let alloc = v.allocator(); unsafe { // Overwrite memory with 4, 5, 6 for i in 0..len { ptr::write(p.add(i), 4 + i); } // Put everything back together into a Vec let rebuilt = Vec::from_raw_parts_in(p, len, cap, alloc.clone()); assert_eq!(rebuilt, [4, 5, 6]); } ``` -------------------------------- ### Implement Clone for SingleConversion Source: https://docs.rs/nowpayments/latest/nowpayments/response/conversion/struct.SingleConversion.html Provides methods for cloning SingleConversion instances. ```rust fn clone(&self) -> SingleConversion ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### PartialEq Implementation for Payout Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/struct.Payout.html Provides methods for comparing two Payout structs for equality. ```rust fn eq(&self, other: &Payout) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### AllPayouts Trait Implementations Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/struct.AllPayouts.html Details the various trait implementations for the `AllPayouts` struct, including Clone, Debug, Default, Deserialize, PartialEq, Serialize, and others. ```APIDOC ## Trait Implementations for AllPayouts ### `impl Clone for AllPayouts` - `fn clone(&self) -> AllPayouts`: Returns a duplicate of the value. - `fn clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. ### `impl Debug for AllPayouts` - `fn fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. ### `impl Default for AllPayouts` - `fn default() -> AllPayouts`: Returns the default value for the type. ### `impl Deserialize for AllPayouts` - `fn begin(__out: &mut Option) -> &mut dyn Visitor`: Implementation for deserialization. ### `impl PartialEq for AllPayouts` - `fn eq(&self, other: &AllPayouts) -> bool`: Tests for equality between two `AllPayouts` instances. - `fn ne(&self, other: &Rhs) -> bool`: Tests for inequality. ### `impl Serialize for AllPayouts` - `fn begin(&self) -> Fragment<'_>`: Implementation for serialization. ### `impl StructuralPartialEq for AllPayouts` ### Auto Trait Implementations - `Freeze`, `RefUnwindSafe`, `Send`, `Sync`, `Unpin`, `UnwindSafe` ### Blanket Implementations - `impl Any for T` - `impl Borrow for T` - `impl BorrowMut for T` - `impl CloneToUninit for T` - `impl From for T` - `impl Instrument for T` - `impl Into for T` - `impl ToOwned for T` - `impl TryFrom for T` - `impl TryInto for T` - `impl WithSubscriber for T` - `impl ErasedDestructor for T` ``` -------------------------------- ### Vec Ordering (Ord) Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Implements lexicographical ordering for Vec where T implements Ord. ```APIDOC ## impl Ord for Vec ### Description Implements ordering of vectors, lexicographically. ### Methods #### fn cmp(&self, other: &Vec) -> Ordering Compares `self` with `other` and returns an `Ordering`. #### fn max(self, other: Self) -> Self Compares two values and returns the maximum. #### fn min(self, other: Self) -> Self Compares two values and returns the minimum. #### fn clamp(self, min: Self, max: Self) -> Self Restricts a value to a specified interval [min, max]. ``` -------------------------------- ### Implement Clone for AllConversions Source: https://docs.rs/nowpayments/latest/nowpayments/response/conversion/struct.AllConversions.html Provides functionality to create a duplicate of an AllConversions value. ```rust fn clone(&self) -> AllConversions ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Implement From Trait Source: https://docs.rs/nowpayments/latest/nowpayments/response/currencies/struct.Currencies.html Provides a conversion from a type to itself. ```rust fn from(t: T) -> T ``` -------------------------------- ### Reconstruct Vec from Raw Parts Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Demonstrates reconstructing a Vec from its raw pointer, length, and capacity. Ensure all safety invariants are met before calling. ```rust #![feature(box_vec_non_null)] use std::ptr::NonNull; use std::mem; let v = vec![1, 2, 3]; // Prevent running `v`'s destructor so we are in complete control // of the allocation. let mut v = mem::ManuallyDrop::new(v); // Pull out the various important pieces of information about `v` let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) }; let len = v.len(); let cap = v.capacity(); unsafe { // Overwrite memory with 4, 5, 6 for i in 0..len { p.add(i).write(4 + i); } // Put everything back together into a Vec let rebuilt = Vec::from_parts(p, len, cap); assert_eq!(rebuilt, [4, 5, 6]); } ``` -------------------------------- ### PartialEq Implementation for FullCurrencies Source: https://docs.rs/nowpayments/latest/nowpayments/response/currencies/struct.FullCurrencies.html Allows for equality comparison between FullCurrencies instances using `==` and `!=` operators. ```rust fn eq(&self, other: &FullCurrencies) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Implement Default for AllConversions Source: https://docs.rs/nowpayments/latest/nowpayments/response/conversion/struct.AllConversions.html Provides a default value for the AllConversions type, useful for initialization. ```rust fn default() -> AllConversions ``` -------------------------------- ### Clone Implementation for Payment Source: https://docs.rs/nowpayments/latest/nowpayments/response/payments/struct.Payment.html Provides methods to duplicate a Payment struct instance. `clone` creates a new, independent copy, while `clone_from` performs an in-place assignment from another Payment instance. ```rust fn clone(&self) -> Payment ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Handle Vec Allocation Errors Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Use `try_reserve_exact` to pre-allocate memory for a Vec and handle potential allocation failures gracefully by returning a `TryReserveError`. ```rust use std::collections::TryReserveError; fn process_data(data: &[u32]) -> Result, TryReserveError> { let mut output = Vec::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve_exact(data.len())?; // Now we know this can't OOM in the middle of our complex work output.extend(data.iter().map(|&val| { val * 2 + 5 // very complicated })); Ok(output) } ``` -------------------------------- ### Deallocating Vector Memory with Box in Rust Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Illustrates how to manually deallocate a vector's backing memory using `Box::from_raw` after wrapping the vector in `ManuallyDrop`. This is necessary to avoid double-freeing when taking ownership of the buffer. ```rust use std::mem::{ManuallyDrop, MaybeUninit}; let mut v = ManuallyDrop::new(vec![0, 1, 2]); let ptr = v.as_mut_ptr(); let capacity = v.capacity(); let slice_ptr: *mut [MaybeUninit] = std::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity); drop(unsafe { Box::from_raw(slice_ptr) }); ``` -------------------------------- ### Implement Freeze for PaymentOpts Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Indicates that the PaymentOpts struct is safe to freeze across threads. ```rust impl Freeze for PaymentOpts ``` -------------------------------- ### Implement Debug for Currencies Source: https://docs.rs/nowpayments/latest/nowpayments/response/currencies/struct.Currencies.html Provides a way to format the Currencies struct for debugging purposes. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### Implement Default for PaymentStatus Source: https://docs.rs/nowpayments/latest/nowpayments/response/payments/struct.PaymentStatus.html Provides a default value for the PaymentStatus struct. This is useful for initializing a PaymentStatus object with sensible default settings when a specific value is not yet known. ```rust fn default() -> PaymentStatus ``` -------------------------------- ### into_parts_with_alloc Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Decomposes a Vec into its raw components: (NonNull pointer, length, capacity, allocator). This is a nightly-only experimental API. ```APIDOC ## pub fn into_parts_with_alloc(self) -> (NonNull, usize, usize, A) ### Description This is a nightly-only experimental API. (`allocator_api`) Decomposes a `Vec` into its raw components: `(NonNull pointer, length, capacity, allocator)`. Returns the `NonNull` pointer to the underlying data, the length of the vector (in elements), the allocated capacity of the data (in elements), and the allocator. These are the same arguments in the same order as the arguments to `from_parts_in`. After calling this function, the caller is responsible for the memory previously managed by the `Vec`. The only way to do this is to convert the `NonNull` pointer, length, and capacity back into a `Vec` with the `from_parts_in` function, allowing the destructor to perform the cleanup. ### Method `pub fn` ### Endpoint N/A (Method on Vec type) ### Parameters None (operates on `self`) ### Request Example ```rust #![feature(allocator_api, vec_into_raw_parts, box_vec_non_null)] use std::alloc::System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` ### Response #### Success Response (Tuple) - `NonNull`: A non-null pointer to the underlying data. - `usize`: The length of the vector (in elements). - `usize`: The allocated capacity of the data (in elements). - `A`: The allocator used by the Vec. #### Response Example (NonNull pointer, length, capacity, allocator) ``` -------------------------------- ### Vec::resize_with Source: https://docs.rs/nowpayments/latest/nowpayments/response/payouts/type.Payouts.html Resizes the Vec in-place using a closure to fill new elements. ```APIDOC ## pub fn resize_with(&mut self, new_len: usize, f: F) where F: FnMut() -> T, ### Description Resizes the `Vec` in-place so that `len` is equal to `new_len`. If `new_len` is greater than `len`, the `Vec` is extended by the difference, with each additional slot filled with the result of calling the closure `f`. The return values from `f` will end up in the `Vec` in the order they have been generated. If `new_len` is less than `len`, the `Vec` is simply truncated. This method uses a closure to create new values on every push. If you’d rather `Clone` a given value, use `Vec::resize`. If you want to use the `Default` trait to generate values, you can pass `Default::default` as the second argument. ### Panics Panics if the new capacity exceeds `isize::MAX` _bytes_. ### Examples ```rust let mut vec = vec![1, 2, 3]; vec.resize_with(5, Default::default); assert_eq!(vec, [1, 2, 3, 0, 0]); let mut vec = vec![]; let mut p = 1; vec.resize_with(4, || { p *= 2; p }); assert_eq!(vec, [2, 4, 8, 16]); ``` ``` -------------------------------- ### Payment Creation Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.NPClient.html Endpoint for creating a new payment. ```APIDOC ## Payment Creation ### Description Creates a new payment transaction. ### Method POST ### Endpoint `/create_payment` (Assumed endpoint based on method name) ### Parameters #### Request Body - **opts** (PaymentOpts) - Required - Options for creating the payment, including amount, currency, and recipient details. ``` -------------------------------- ### PaymentOpts Struct Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Details the PaymentOpts struct, which is used to configure payment options. It includes its constructor and associated implementations. ```APIDOC ## Struct PaymentOpts nowpayments::client ### Summary ```rust pub struct PaymentOpts { /* private fields */ } ``` ### Implementations #### impl PaymentOpts ##### pub fn new( price_amount: u32, price_currency: impl Display, pay_currency: impl Display, ipn_callback_url: impl Display, order_id: impl Display, order_description: impl Display, ) -> Self This function constructs a new `PaymentOpts` instance with the provided payment details. ``` -------------------------------- ### Implement PartialEq for SingleConversion Source: https://docs.rs/nowpayments/latest/nowpayments/response/conversion/struct.SingleConversion.html Allows for equality comparison between SingleConversion instances. ```rust fn eq(&self, other: &SingleConversion) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Implement From for T Source: https://docs.rs/nowpayments/latest/nowpayments/client/struct.PaymentOpts.html Provides a trivial conversion from a type T to itself. ```rust impl From for T ``` -------------------------------- ### MinPaymentAmount Struct Source: https://docs.rs/nowpayments/latest/nowpayments/response/payments/struct.MinPaymentAmount.html Details about the MinPaymentAmount struct used in NOWPayments API responses. ```APIDOC ## Struct MinPaymentAmount ### Description Represents the minimum payment amount information returned by the NOWPayments API. ### Fields This struct has private fields and is primarily used for deserialization from API responses. ### Example Usage ```rust // Assuming you have received a JSON response from the NOWPayments API // let response_json = r#"{"some_field": "some_value"}"#; // let min_payment_amount: MinPaymentAmount = serde_json::from_str(response_json).unwrap(); ``` ### Trait Implementations * **Debug**: Allows the struct to be formatted for debugging. * **Deserialize**: Enables deserialization from formats like JSON. * **Serialize**: Allows serialization into formats like JSON. ### Auto Trait Implementations * **Freeze**, **RefUnwindSafe**, **Send**, **Sync**, **Unpin**, **UnwindSafe**: Standard Rust safety and concurrency traits. ### Blanket Implementations * **Any**: Provides type information. * **Borrow**, **BorrowMut**: Allows borrowing of the struct. * **From**: Conversion from the same type. * **Instrument**, **InCurrentSpan**: For tracing and logging. * **Into**, **TryFrom**, **TryInto**: Conversion traits. * **WithSubscriber**, **WithCurrentSubscriber**: For integrating with subscribers. ```