Struct Object

Source
pub struct Object { /* private fields */ }

Implementations§

Source§

impl Object

Source

pub fn new( device_content: Content, id: U16CString, name: U16CString, ty: ObjectType, ) -> Self

Source

pub fn id(&self) -> &U16CStr

Source

pub fn name(&self) -> &U16CStr

Source

pub fn object_type(&self) -> ObjectType

Source

pub fn properties( &self, properties_to_fetch: &[PROPERTYKEY], ) -> WindowsResult<DeviceValues>

Get a list of requested metadata about an object.

See crate::device::Content::properties.

Source

pub fn parent_id(&self) -> WindowsResult<U16CString>

Source

pub fn children(&self) -> WindowsResult<ObjectIterator<'_>>

Returns an iterator to list every children of the current object (including sub-folders)

Examples found in repository?
examples/list-devices.rs (line 33)
24fn show_content(basic_device: &BasicDevice) -> Result<(), Box<dyn Error>> {
25    let app_ident = winmtp::make_current_app_identifiers!();
26
27    let device = basic_device.open(&app_ident, true)?;
28    let content = device.content()?;
29
30    let root_obj = content.root()?;
31    println!("root: {:?}", root_obj);
32
33    for child in root_obj.children()? {
34        println!("  * {:?}", child);
35    }
36    Ok(())
37}
Source

pub fn sub_folders(&self) -> WindowsResult<impl Iterator<Item = Object> + '_>

Returns an iterator that only lists folders within this object

Source

pub fn object_by_path( &self, relative_path: &Path, ) -> Result<Object, ItemByPathError>

Retrieve an item by its path

This function looks for a sub-item with the right name, then iteratively does so for the matching child.
This is quite expensive. Depending on your use-cases, you may want to cache some “parent folders” that you will want to access often.
Note that caching however defeats the purpose of MTP, which is supposed to not use any cache, so that it guarantees there is no race between concurrent accesses to the same medium.

Source

pub fn open_raw_stream( &self, stream_mode: STGM, ) -> Result<(IStream, u32), OpenStreamError>

Opens a COM IStream to this object.

An error will be returned if the required operation does not make sense (e.g. get a stream to a folder).

Also returns the optimal transfer buffer size (in bytes) for this transfer, as stated by the Microsoft API.

See also Self::open_read_stream.

Source

pub fn open_read_stream(&self) -> Result<BufReader<ReadStream>, OpenStreamError>

The same as Self::open_raw_stream, but wrapped into a crate::io::ReadStream for more added Rust magic.

§Example
let object = device.content().unwrap().object_by_id(some_id).unwrap();
let mut input_stream = object.open_read_stream().unwrap();
let mut output_file = std::fs::File::create("pulled-from-device.dat").unwrap();
std::io::copy(&mut input_stream, &mut output_file).unwrap();
Source

pub fn create_subfolder( &self, folder_name: &OsStr, ) -> Result<U16CString, CreateFolderError>

Create a subfolder, and return its object ID

If a folder with the same name already exists (“same name” depends on the chosen case-folding mode), an CreateFolderError::AlreadyExists error will be returned.

See also Self::create_subfolder_recursive

Source

pub fn create_subfolder_recursive( &self, folder_path: &Path, ) -> Result<(), CreateFolderError>

Create a path of folders, creating intermediate folders if needed

Source

pub fn push_file( &self, local_file: &Path, allow_overwrite: bool, ) -> Result<(), AddFileError>

Add a file into the current directory

Source

pub fn push_data( &self, file_name: &OsStr, data: &[u8], allow_overwrite: bool, ) -> Result<(), AddFileError>

Add a file into the current directory

Source

pub fn delete(&mut self, recursive: bool) -> WindowsResult<()>

Delete an object

If this is a folder, you must set recursive to true, otherwise this would return an error.

Source

pub fn move_to(&mut self, new_folder_id: &U16CStr) -> WindowsResult<()>

Move an object that is already on the device to a new folder

Trait Implementations§

Source§

impl Clone for Object

Source§

fn clone(&self) -> Object

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 Debug for Object

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl !Send for Object

§

impl !Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.