mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
dialogs: use Cow<str>
to avoid cloning a String
This commit is contained in:
parent
3ea45e57d8
commit
130288beb4
@ -1,4 +1,7 @@
|
||||
use std::io::{self, Write};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
io::{self, Write},
|
||||
};
|
||||
|
||||
use crate::utils::colors;
|
||||
|
||||
@ -15,9 +18,9 @@ impl<'a> Confirmation<'a> {
|
||||
|
||||
pub fn ask(&self, substitute: Option<&'a str>) -> crate::Result<bool> {
|
||||
let message = match (self.placeholder, substitute) {
|
||||
(None, _) => self.prompt.into(),
|
||||
(None, _) => Cow::Borrowed(self.prompt),
|
||||
(Some(_), None) => return Err(crate::Error::InternalError),
|
||||
(Some(placeholder), Some(subs)) => self.prompt.replace(placeholder, subs),
|
||||
(Some(placeholder), Some(subs)) => Cow::Owned(self.prompt.replace(placeholder, subs)),
|
||||
};
|
||||
|
||||
loop {
|
||||
|
Loading…
x
Reference in New Issue
Block a user