diff options
Diffstat (limited to 'crates/shirabe/src/io')
| -rw-r--r-- | crates/shirabe/src/io/buffer_io.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/io/console_io.rs | 18 | ||||
| -rw-r--r-- | crates/shirabe/src/io/io_interface.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/io/null_io.rs | 6 |
4 files changed, 21 insertions, 13 deletions
diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs index ed87b71..291b64b 100644 --- a/crates/shirabe/src/io/buffer_io.rs +++ b/crates/shirabe/src/io/buffer_io.rs @@ -245,7 +245,11 @@ impl crate::io::IOInterfaceMutable for BufferIO { } } -impl crate::io::IOInterface for BufferIO {} +impl crate::io::IOInterface for BufferIO { + fn as_any(&self) -> &dyn std::any::Any { + self + } +} impl crate::io::BaseIO for BufferIO { fn authentications( diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs index 2b1c334..b69b68b 100644 --- a/crates/shirabe/src/io/console_io.rs +++ b/crates/shirabe/src/io/console_io.rs @@ -142,10 +142,7 @@ impl ConsoleIO { messages }; - if true == stderr && self.output.is_console_output_interface() { - // TODO(phase-b): downcast Box<dyn OutputInterface> to ConsoleOutputInterface - let console_output: &dyn ConsoleOutputInterface = - todo!("downcast self.output to ConsoleOutputInterface"); + if stderr && let Some(console_output) = self.output.as_console_output_interface() { console_output.get_error_output().write( &Self::to_string_list(&messages).join(if newline { "\n" } else { "" }), newline, @@ -263,11 +260,8 @@ impl ConsoleIO { } fn get_error_output(&self) -> &dyn OutputInterface { - if self.output.is_console_output_interface() { - // TODO(phase-b): downcast Box<dyn OutputInterface> to ConsoleOutputInterface - return todo!( - "downcast self.output to ConsoleOutputInterface and call get_error_output()" - ); + if let Some(console_output) = self.output.as_console_output_interface() { + return console_output.get_error_output(); } &*self.output @@ -677,7 +671,11 @@ impl IOInterfaceMutable for ConsoleIO { } } -impl IOInterface for ConsoleIO {} +impl IOInterface for ConsoleIO { + fn as_any(&self) -> &dyn std::any::Any { + self + } +} impl BaseIO for ConsoleIO { fn authentications( diff --git a/crates/shirabe/src/io/io_interface.rs b/crates/shirabe/src/io/io_interface.rs index aac1488..e48f9ce 100644 --- a/crates/shirabe/src/io/io_interface.rs +++ b/crates/shirabe/src/io/io_interface.rs @@ -149,7 +149,9 @@ pub trait IOInterfaceMutable { // PHP `IOInterface`. This is the type used for the shared trait object // `dyn IOInterface`; its vtable carries both the immutable and mutable methods. -pub trait IOInterface: IOInterfaceImmutable + IOInterfaceMutable {} +pub trait IOInterface: IOInterfaceImmutable + IOInterfaceMutable { + fn as_any(&self) -> &dyn std::any::Any; +} // Shared-ownership handle for a PHP IO instance (reference semantics). It // exposes only the immutable surface; mutating methods (`set_authentication`, diff --git a/crates/shirabe/src/io/null_io.rs b/crates/shirabe/src/io/null_io.rs index b0e11f1..85a5fa5 100644 --- a/crates/shirabe/src/io/null_io.rs +++ b/crates/shirabe/src/io/null_io.rs @@ -138,7 +138,11 @@ impl IOInterfaceMutable for NullIO { } } -impl IOInterface for NullIO {} +impl IOInterface for NullIO { + fn as_any(&self) -> &dyn std::any::Any { + self + } +} impl BaseIO for NullIO { fn authentications( |
