Skip to content

Commit

Permalink
Broaden &str parameter type to AsRef<Path>
Browse files Browse the repository at this point in the history
In case client code wants to use methods with a PathBuf or Path.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Mar 28, 2017
1 parent 01be152 commit 24026db
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::fs::File;

use std::os::unix::prelude::*;
use std::io;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use libc::{c_int, ioctl, uint8_t, uint32_t, uint64_t};
use std::default::Default;

Expand Down Expand Up @@ -80,7 +80,7 @@ pub struct LoopDevice {

impl LoopDevice {
/// Opens a loop device.
pub fn open(dev: &str) -> io::Result<LoopDevice> {
pub fn open<P: AsRef<Path>>(dev: P) -> io::Result<LoopDevice> {
// TODO create dev if it does not exist and begins with LOOP_PREFIX
let f = try!(OpenOptions::new().read(true).write(true).open(dev));
Ok(LoopDevice { device: f })
Expand All @@ -98,7 +98,7 @@ impl LoopDevice {
/// ld.attach("test.img", 0).unwrap();
/// # ld.detach().unwrap();
/// ```
pub fn attach(&self, backing_file: &str, offset: u64) -> io::Result<()> {
pub fn attach<P: AsRef<Path>>(&self, backing_file: P, offset: u64) -> io::Result<()> {
let bf = try!(OpenOptions::new().read(true).write(true).open(backing_file));

// Attach the file
Expand Down

0 comments on commit 24026db

Please sign in to comment.