Георги качи първо решение на 18.12.2018 14:02 (преди почти 7 години)
Смислено решение, но трябваше да прочетеш по-внимателно условието.
Compiling solution v0.1.0 (/tmp/d20190123-22631-liiqkk/solution)
Finished dev [unoptimized + debuginfo] target(s) in 4.74s
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 ... ok
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 ... ok
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: `"OneTwoThree"`,
right: `"One\nTwo\nThree\n"`', tests/solution_test.rs:219:5
---- solution_test::test_cloning_a_logger_shares_their_io stdout ----
thread 'solution_test::test_cloning_a_logger_shares_their_io' panicked at 'assertion failed: `(left == right)`
left: `"First\nSecond\nThird"`,
right: `"First\nSecond\nThird\n"`', tests/solution_test.rs:175:5
---- 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 'assertion failed: `(left == right)`
left: `"[Base1] [Multi] Test entry[Base2] [Multi] Test entry"`,
right: `"[Base1] [Multi] Test entry\n[Base2] [Multi] Test entry\n"`', tests/solution_test.rs:268:5
---- solution_test::test_multilogger_logs_to_several_ios stdout ----
thread 'solution_test::test_multilogger_logs_to_several_ios' panicked at 'assertion failed: `(left == right)`
left: `"One\nTwo"`,
right: `"One\nTwo\n"`', tests/solution_test.rs:241:5
---- 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 'assertion failed: `(left == right)`
left: `"[First] One\n[Second] Two\n[Second] Three\n[First] Four"`,
right: `"[First] One\n[Second] Two\n[Second] Three\n[First] Four\n"`', tests/solution_test.rs:315:5
---- solution_test::test_scoped_logger_with_a_string_tag stdout ----
thread 'solution_test::test_scoped_logger_with_a_string_tag' panicked at 'assertion failed: `(left == right)`
left: `"[First] Test"`,
right: `"[First] Test\n"`', tests/solution_test.rs:329:5
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_their_io
solution_test::test_flushing_the_buffer
solution_test::test_logger_combinations
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. 6 passed; 9 failed; 0 ignored; 0 measured; 0 filtered out
error: test failed, to rerun pass '--test solution_test'
Смислено решение, но трябваше да прочетеш по-внимателно условието.
Правилно си имплементирал тези два метода директно в trait-а.
Интересно решение да "енкапсуловаш" двата компонента на споделянето. Може би е малко overkill в ситуацията.
Специално написахме в условието (секция "Писане във "файл"), че всеки запис трябва да завършва на
\n:). Join-ването не добавя нов ред накрая на последния елемент. Можеше да сложиш едноself.out.borrow_mut().write(b"\n")примерно.