File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 1- use std:: ffi:: OsString ;
1+ use std:: ffi:: { OsStr , OsString } ;
22
33use crate :: path:: Path ;
44
@@ -123,6 +123,35 @@ impl PathBuf {
123123 pub fn push < P : AsRef < std:: path:: Path > > ( & mut self , path : P ) {
124124 self . inner . push ( path)
125125 }
126+
127+ /// Updates [`self.extension`] to `extension`.
128+ ///
129+ /// Returns `false` and does nothing if [`self.file_name`] is [`None`],
130+ /// returns `true` and updates the extension otherwise.
131+ ///
132+ /// If [`self.extension`] is [`None`], the extension is added; otherwise
133+ /// it is replaced.
134+ ///
135+ /// [`self.file_name`]: struct.PathBuf.html#method.file_name
136+ /// [`self.extension`]: struct.PathBuf.html#method.extension
137+ /// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
138+ ///
139+ /// # Examples
140+ ///
141+ /// ```
142+ /// use async_std::path::{Path, PathBuf};
143+ ///
144+ /// let mut p = PathBuf::from("/feel/the");
145+ ///
146+ /// p.set_extension("force");
147+ /// assert_eq!(Path::new("/feel/the.force"), p.as_path());
148+ ///
149+ /// p.set_extension("dark_side");
150+ /// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path());
151+ /// ```
152+ pub fn set_extension < S : AsRef < OsStr > > ( & mut self , extension : S ) -> bool {
153+ self . inner . set_extension ( extension)
154+ }
126155}
127156
128157impl From < std:: path:: PathBuf > for PathBuf {
You can’t perform that action at this time.
0 commit comments