vs the PHP CGWebFramework
This starter is the Rust implementation of the PHP project: the browser's JavaScript, CSS and component HTML are the same files (brought over by the sync script), and the server-side protocol (endpoints, fields, error shapes, action names) is rewritten after the PHP version. If you already know the PHP version, most of that knowledge carries over; the differences are mostly "what PHP declares with attributes, Rust writes in code".
The whole picture
| PHP version | Rust starter | |
|---|---|---|
| Back-end framework | Laravel | Laravel for Rust 0.1.4 (beta) |
| Templates | Blade (@renderObject, @linker…) | MiniJinja + Rust builders; runtime attributes produced by handlers |
| Components | Dozens (Badge, Button, Modal, Table, Chart, FileDrop…) | Badge, Button, Icon |
| Fragment allow list | Controllers using CanRenderCallSafely | Names registered with render::register("name", async fn) |
| Linker method allow list | #[Computable] | The METHODS constant |
| Argument validation | #[Validate([...])]; undeclared keys are rejected | Read and validate them yourself in call; args is the whole map |
| Login | #[RequiresAuth]; anonymous possible | Always required (401 without a user) |
| Email verification | #[RequiresVerified] | Check in call, return LinkerResponse::policy(messages::UNVERIFIED) |
| Authorization | #[Authorize('view', Model::class, arg: 'id')] | user.authorize(Policy::view, &model).await? |
| Referer allow list | allowsRefererUrls(): paths or route names; require_referer configurable | ALLOWS_REFERER_URLS: path patterns only; requests without a Referer are always allowed |
| Lifetimes | config/linker.php + environment variables | Constants: 30 min idle, 90 s renewal, 8 h maximum, 0.8 s minimum interval |
| Instance lock | Configurable lease and wait | Fixed 60 s lease, 3 s wait |
| Caching method results | #[Computable(cache: true)] | None; use cache::remember yourself, and the key must include the user |
| Fragment fingerprints | xxh128 | SHA-256 (first 16 bytes); the browser only compares strings, so behavior is the same |
| Endpoint meta | Absolute URLs | Relative paths; no difference for same-origin use |
| Pagination rebase, HTML minification | Yes | No |
dump() / dd() debug panel | Yes | No; use eprintln! or tracing |
@renderInline | Yes | No; call your render function in the handler and put the HTML in the template |
| Adding actions | make:linker-action generates both PHP and JS | Action::new("name", args) + register in JS; see Actions |
| CLI audit | php artisan linker:list | None; see the grep audits in Commands |
What stays the same
- The browser side is identical. The meaning of
data-render-*,data-state-*anddata-linker-*,state.js,linker.jsand the JS implementations of the action table are the PHP project's own files. - The error kinds are the same.
validation,policy,expired,conflict,service,fatal, with one handler in the browser. - The two modes are the same. Stateful (the server stores the instance, the browser has only uuid + rev) and Stateless (signed URLs).
- The render token and fingerprint protocol is the same. One-time tokens, a pool of 16,
unchangedwhen the content hasn't changed. - The endpoint prefix is derived the same way. HMAC-SHA256 of
APP_KEY; PHP and Rust with the same key get the same prefix.
The same Linker written both ways
PHP:
php
#[RequiresAuth]
class CounterLinker extends LinkerComponent
{
public static string $alias = 'counter';
#[Computable]
#[Validate(['step' => 'required|integer|between:1,100'])]
public function setStep(array $args): LinkerResponse
{
$this->set('step', (int) $args['step']);
return $this->ok(['step' => $this->get('step')]);
}
}Rust:
rust
#[derive(Default, Serialize, Deserialize)]
pub struct Counter {
pub count: i64,
pub step: i64,
}
impl LinkerComponent for Counter {
const ALIAS: &'static str = "counter";
const METHODS: &'static [&'static str] = &["increment", "reset", "setStep"];
async fn call(&mut self, _: &LinkerContext, method: &str, args: Args) -> laravel::Result<LinkerResponse> {
match method {
"setStep" => {
let step = args
.get("step")
.and_then(|v| v.as_str()?.parse::<i64>().ok().or(v.as_i64()));
match step {
Some(step) if (1..=100).contains(&step) => self.step = step,
_ => return Ok(LinkerResponse::validation([("step", "The step must be an integer from 1 to 100.")])),
}
}
// …
_ => unreachable!("METHODS lists every method"),
}
Ok(LinkerResponse::ok().data("step", self.step))
}
}The differences:
- State is the struct's fields (
Serialize + Deserialize), not key-value pairs through$this->set(). METHODSreplaces#[Computable]; methods not in the list are blocked beforecall, so the_arm of thematchcan beunreachable!.- Validation is inside the method; on failure return
LinkerResponse::validationwith messages you write.
Which one
- The team works mainly in PHP and needs the full component library → the PHP version.
- The back end is already Rust, you need only a few components and are willing to port the missing ones → this starter.
- Sharing screens between both: the same snapshots are the single source of truth for both, and the Rust parity tests tell you whether they match.