File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -359,11 +359,12 @@ known at compile time. (This is one of the dyn compatibility rules mentioned
359359earlier.)
360360
361361Other duplication includes the similar implementations of the ` request_review `
362- and ` approve ` methods on ` Post ` . Both methods delegate to the implementation of
363- the same method on the value in the ` state ` field of ` Option ` and set the new
364- value of the ` state ` field to the result. If we had a lot of methods on ` Post `
365- that followed this pattern, we might consider defining a macro to eliminate the
366- repetition (see [ “Macros”] [ macros ] <!-- ignore --> in Chapter 20).
362+ and ` approve ` methods on ` Post ` . Both methods use ` Option::take ` with the
363+ ` state ` field of ` Post ` , and if ` state ` is ` Some ` , they delegate to the wrapped
364+ value’s implementation of the same method and set the new value of the ` state `
365+ field to the result. If we had a lot of methods on ` Post ` that followed this
366+ pattern, we might consider defining a macro to eliminate the repetition (see
367+ [ “Macros”] [ macros ] <!-- ignore --> in Chapter 20).
367368
368369By implementing the state pattern exactly as it’s defined for object-oriented
369370languages, we’re not taking as full advantage of Rust’s strengths as we could.
You can’t perform that action at this time.
0 commit comments