Cursor rule
.cursor/rules/api-design.mdcAPI design principles and patterns for skia-rs
Cursor rules
Quality
58/100
Scores the file, not the repository.Length
353 words
9 headings · 5 code blocksRepository
28
— · pushed 21 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# API Design Principles89## Skia API Compatibility1011The primary goal is API compatibility with Skia. When implementing a feature:12131. **Reference the original**: Check `skia/` submodule for the C++ implementation142. **Match signatures**: Function names and parameter order should match Skia153. **Match semantics**: Behavior should be identical to Skia164. **Document differences**: If Rust requires a different approach, document it1718## Builder Pattern1920Use builders for complex object construction:2122```rust23pub struct PathBuilder {24 path: Path,25 last_move: Option<Point>,26}2728impl PathBuilder {29 pub fn new() -> Self { ... }30 pub fn move_to(&mut self, x: Scalar, y: Scalar) -> &mut Self { ... }31 pub fn line_to(&mut self, x: Scalar, y: Scalar) -> &mut Self { ... }32 pub fn build(self) -> Path { ... }33}34```3536## Method Chaining3738Support fluent interfaces where appropriate:3940```rust41impl Paint {42 pub fn set_color(&mut self, color: Color4f) -> &mut Self {43 self.color = color;44 self45 }4647 pub fn set_style(&mut self, style: Style) -> &mut Self {48 self.style = style;49 self50 }51}5253// Usage:54paint.set_color(Color4f::RED)55 .set_style(Style::Stroke)56 .set_stroke_width(2.0);57```5859## Const Correctness6061- Use `const fn` where possible62- Define common constants as associated constants6364```rust65impl Rect {66 pub const EMPTY: Self = Self { left: 0.0, top: 0.0, right: 0.0, bottom: 0.0 };6768 #[inline]69 pub const fn new(left: Scalar, top: Scalar, right: Scalar, bottom: Scalar) -> Self {70 Self { left, top, right, bottom }71 }72}73```7475## Common Patterns7677### Cloning vs Referencing7879- Prefer references for read-only access80- Clone only when ownership transfer is needed81- Use `Cow<T>` when clone-on-write is beneficial8283### Option Patterns8485```rust86// Skia-style: return Option for fallible operations87pub fn invert(&self) -> Option<Matrix> {88 let det = self.determinant();89 if det == 0.0 {90 return None;91 }92 Some(self.compute_inverse(det))93}94```9596### Iteration9798```rust99// Provide iterators for collections100impl Path {101 pub fn iter(&self) -> PathIter<'_> {102 PathIter { path: self, index: 0 }103 }104}105106// Make types iterable107impl<'a> IntoIterator for &'a Path {108 type Item = PathElement;109 type IntoIter = PathIter<'a>;110111 fn into_iter(self) -> Self::IntoIter {112 self.iter()113 }114}115```116
Also in quinnjr/skia-rs
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| quinnjr/skia-rs.cursor/rules/ffi.mdc · 28 | Cursor rules | typesapi | 45/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/architecture.mdc · 28 | Cursor rules | archdependenciesmonorepo | 62/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/benchmarking.mdc · 28 | Cursor rules | styleperformance | 69/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/code-style.mdc · 28 | Cursor rules | styletypesperformancedeployment+1 | 62/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/commands.mdc · 28 | Cursor rules | buildtestlint-formatgit+4 | 82/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/fuzzing.mdc · 28 | Cursor rules | setupstyle | 69/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/gpu.mdc · 28 | Cursor rules | no sections | 36/100 | 3 days ago | |
| quinnjr/skia-rs.cursor/rules/testing.mdc · 28 | Cursor rules | test | 69/100 | 3 days ago |
Diff against .cursor/rules/ffi.mdc Diff against .cursor/rules/architecture.mdc Diff against .cursor/rules/benchmarking.mdc Diff against .cursor/rules/code-style.mdc Diff against .cursor/rules/commands.mdc Diff against .cursor/rules/fuzzing.mdc Diff against .cursor/rules/gpu.mdc Diff against .cursor/rules/testing.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
