[PATCH v2 1/2] rust: replace length checks with match