Мария качи първо решение на 18.12.2018 09:19 (преди над 4 години)
Обещаващо начало на решение, но недовършено. Другия път почвай по-отрано със задачата.
Compiling solution v0.1.0 (/tmp/d20190123-22631-1ffem1c/solution) warning: unused variable: `time` --> src/lib.rs:108:24 | 108 | fn push(&mut self, time: Instant, text: &str) { | ^^^^ help: consider using `_time` instead | = note: #[warn(unused_variables)] on by default warning: unused variable: `text` --> src/lib.rs:108:39 | 108 | fn push(&mut self, time: Instant, text: &str) { | ^^^^ help: consider using `_text` instead warning: unused variable: `time` --> src/lib.rs:108:24 | 108 | fn push(&mut self, time: Instant, text: &str) { | ^^^^ help: consider using `_time` instead | = note: #[warn(unused_variables)] on by default warning: unused variable: `text` --> src/lib.rs:108:39 | 108 | fn push(&mut self, time: Instant, text: &str) { | ^^^^ help: consider using `_text` instead Finished dev [unoptimized + debuginfo] target(s) in 5.31s Running target/debug/deps/solution-2e785d603b538f71 running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out Running target/debug/deps/solution_test-29808948fb50ed3a running 15 tests test solution_test::test_automatic_flushing_when_buffer_limit_is_reached ... FAILED test solution_test::test_automatic_flushing_when_zero_buffer_limit ... FAILED test solution_test::test_basic_log ... ok test solution_test::test_basic_push ... ok test solution_test::test_cloning_a_logger_shares_a_buffer ... FAILED test solution_test::test_cloning_a_logger_shares_their_io ... FAILED test solution_test::test_erroring_io ... ok test solution_test::test_flushing_the_buffer ... FAILED test solution_test::test_logger_combinations ... FAILED test solution_test::test_multilogger_logs_and_flushes_when_needed ... FAILED test solution_test::test_multilogger_logs_to_several_ios ... FAILED test solution_test::test_reordering_logs_in_buffer ... ok test solution_test::test_reordering_logs_in_io ... FAILED test solution_test::test_scoped_logger ... FAILED test solution_test::test_scoped_logger_with_a_string_tag ... FAILED failures: ---- solution_test::test_automatic_flushing_when_buffer_limit_is_reached stdout ---- thread 'solution_test::test_automatic_flushing_when_buffer_limit_is_reached' panicked at 'assertion failed: `(left == right)` left: `"One\nTwo\nThree"`, right: `"One\nTwo\nThree\n"`', tests/solution_test.rs:200:5 note: Run with `RUST_BACKTRACE=1` for a backtrace. ---- solution_test::test_automatic_flushing_when_zero_buffer_limit stdout ---- thread 'solution_test::test_automatic_flushing_when_zero_buffer_limit' panicked at 'assertion failed: `(left == right)` left: `1`, right: `0`', tests/solution_test.rs:210:9 ---- solution_test::test_cloning_a_logger_shares_a_buffer stdout ---- thread 'solution_test::test_cloning_a_logger_shares_a_buffer' panicked at 'not yet implemented', src/lib.rs:49:9 ---- solution_test::test_cloning_a_logger_shares_their_io stdout ---- thread 'solution_test::test_cloning_a_logger_shares_their_io' panicked at 'not yet implemented', src/lib.rs:49:9 ---- solution_test::test_flushing_the_buffer stdout ---- thread 'solution_test::test_flushing_the_buffer' panicked at 'assertion failed: `(left == right)` left: `"Some warning\nSome other warning"`, right: `"Some warning\nSome other warning\n"`', tests/solution_test.rs:95:5 ---- solution_test::test_logger_combinations stdout ---- thread 'solution_test::test_logger_combinations' panicked at 'not yet implemented', src/lib.rs:49:9 ---- solution_test::test_multilogger_logs_and_flushes_when_needed stdout ---- thread 'solution_test::test_multilogger_logs_and_flushes_when_needed' panicked at 'not yet implemented', src/lib.rs:49:9 ---- solution_test::test_multilogger_logs_to_several_ios stdout ---- thread 'solution_test::test_multilogger_logs_to_several_ios' panicked at 'not yet implemented', src/lib.rs:109:9 ---- solution_test::test_reordering_logs_in_io stdout ---- thread 'solution_test::test_reordering_logs_in_io' panicked at 'assertion failed: `(left == right)` left: `"First\nSecond\nThird\nFourth"`, right: `"First\nSecond\nThird\nFourth\n"`', tests/solution_test.rs:134:5 ---- solution_test::test_scoped_logger stdout ---- thread 'solution_test::test_scoped_logger' panicked at 'not yet implemented', src/lib.rs:49:9 ---- solution_test::test_scoped_logger_with_a_string_tag stdout ---- thread 'solution_test::test_scoped_logger_with_a_string_tag' panicked at 'not yet implemented', src/lib.rs:49:9 failures: solution_test::test_automatic_flushing_when_buffer_limit_is_reached solution_test::test_automatic_flushing_when_zero_buffer_limit solution_test::test_cloning_a_logger_shares_a_buffer solution_test::test_cloning_a_logger_shares_their_io solution_test::test_flushing_the_buffer solution_test::test_logger_combinations solution_test::test_multilogger_logs_and_flushes_when_needed solution_test::test_multilogger_logs_to_several_ios solution_test::test_reordering_logs_in_io solution_test::test_scoped_logger solution_test::test_scoped_logger_with_a_string_tag test result: FAILED. 4 passed; 11 failed; 0 ignored; 0 measured; 0 filtered out error: test failed, to rerun pass '--test solution_test'
Обещаващо начало на решение, но недовършено. Другия път почвай по-отрано със задачата.
Бих сложил декларацията на функцията и имплементацията на различни редове.
LoggerEntity { LoggerEntity {
ми отне известно време и объркване, докато схвана какво се случва.Ако buffer_size е подадено като 0, това никога няма да се извика. Често срещана грешка в решенията, изглежда. Тук искаш
>=
.Можеше във
flush
да извикашtry_flush
, и ако от него дойде грешка, да печаташ. Нещо повече, методаtry_flush
можеше да бъде имплементиран веднъж по този начин в trait-a.