Commit ff58b6a
committed
refactor: implement Phase 1 DRY improvements
This commit implements the low-hanging fruit refactorings from the DRY
analysis report, focusing on eliminating code duplication with minimal risk.
Changes:
1. Unify bytes_to_string() function
- Moved implementation to util/text.rs as single source of truth
- Removed duplicate implementations from parser/common.rs and types/common.rs
- Added comprehensive documentation with examples
- Re-exported from parser/common for backward compatibility
- Lines saved: ~8
2. Add Person::from_name() helper method
- Added convenience constructor for creating Person from just a name
- Updated all 4 occurrences in namespace/dublin_core.rs to use helper
- Reduces boilerplate and ensures consistent Person construction
- Lines saved: ~10
3. Use Tag::new() builder method consistently
- Tag::new() already existed but wasn't used everywhere
- Updated 4 occurrences across namespace modules to use builder
- Replaced verbose struct literal construction with concise builder
- Lines saved: ~12
4. Add HTTP header helper method
- Added insert_header() helper to reduce boilerplate in FeedHttpClient
- Centralizes error handling for header value conversion
- Updated get() method to use helper for User-Agent, ETag, and Last-Modified
- Consistent error messages across all header insertions
- Lines saved: ~15
Total impact:
- Lines reduced: ~45
- Files modified: 6
- Test coverage: All 302 tests pass
- Clippy: Clean with -D warnings
- Risk level: Low (backward compatible changes only)
These changes improve code maintainability and reduce the risk of
inconsistent behavior when similar operations are performed in different
parts of the codebase.1 parent d8ab141 commit ff58b6a
File tree
6 files changed
+89
-84
lines changed- crates/feedparser-rs-core/src
- http
- namespace
- parser
- types
- util
6 files changed
+89
-84
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
66 | 86 | | |
67 | 87 | | |
68 | 88 | | |
| |||
91 | 111 | | |
92 | 112 | | |
93 | 113 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 114 | + | |
100 | 115 | | |
101 | 116 | | |
102 | 117 | | |
| |||
112 | 127 | | |
113 | 128 | | |
114 | 129 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 130 | + | |
121 | 131 | | |
122 | 132 | | |
123 | 133 | | |
124 | | - | |
| 134 | + | |
| 135 | + | |
125 | 136 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
130 | 140 | | |
131 | 141 | | |
132 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 42 | + | |
47 | 43 | | |
48 | 44 | | |
49 | 45 | | |
| |||
55 | 51 | | |
56 | 52 | | |
57 | 53 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 54 | + | |
63 | 55 | | |
64 | 56 | | |
65 | 57 | | |
| |||
101 | 93 | | |
102 | 94 | | |
103 | 95 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 96 | + | |
109 | 97 | | |
110 | 98 | | |
111 | 99 | | |
| |||
127 | 115 | | |
128 | 116 | | |
129 | 117 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 118 | + | |
135 | 119 | | |
136 | 120 | | |
137 | 121 | | |
| |||
144 | 128 | | |
145 | 129 | | |
146 | 130 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 131 | + | |
152 | 132 | | |
153 | 133 | | |
154 | 134 | | |
| |||
166 | 146 | | |
167 | 147 | | |
168 | 148 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 149 | + | |
174 | 150 | | |
175 | 151 | | |
176 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 49 | + | |
54 | 50 | | |
55 | 51 | | |
56 | 52 | | |
57 | 53 | | |
58 | 54 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 55 | + | |
64 | 56 | | |
65 | 57 | | |
66 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 110 | | |
122 | 111 | | |
123 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 5 | | |
14 | 6 | | |
15 | 7 | | |
| |||
99 | 91 | | |
100 | 92 | | |
101 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
102 | 117 | | |
103 | 118 | | |
104 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments