DEV Community


Discussion on: Web Development with Rust— 02/x: Deploy your first App

franky47 profile image
François Best • Edited

Thanks for the article !

I'm looking into Zeit Now for Rust, but I have a few issues with it:

  • It does not follow standard crates filesystem recommendations, but rather takes a Next.js approach of using filesystem = routes, which means you end up with your endpoint at I see you defined src/ in now.json, but no such file exists, how does this work ?
  • For this reason, I found it hard to integrate serverless endpoints in an existing codebase that uses Cargo workspaces, because that "crate" won't actually compile.
gruberb profile image
Bastian Gruber Author

Thanks Francois! I changed the filename:

You are right, serverless mindest is different than a typical cargo app. You can follow the official documentation here:

As I mentioned in the article: You don't really create an app when thinking in serverless terms, but you just invoke functions/handlers which process data.

The ZEIT environment will idle your application when it's not needed and start it when triggered (an endpoint is called).

franky47 profile image
François Best • Edited

What I meant was that in a real-world case, your serverless endpoint/function will probably want to use business/domain/applicative code that is located and organised elsewhere, in Cargo workspaces, and Zeit's approach does not play well with that.

One way that could work would be to have a directory structure as follows:

├── workspace
│ ├── Cargo.toml      Workspace root definition
│ ├── Cargo.lock      Shared lockfile
│ ├── target/         Shared build directory
│ ├── foo
│ └── bar
└── serverless        Zeit Now endpoints
  ├── baz
  | ├── Cargo.toml    [dependencies] foo = { path = "../../workspace/foo" }
  | └──
  └── qux
    ├── Cargo.toml    [dependencies] bar = { path = "../../workspace/bar" }

Edit: after a quick test, this cannot work either, if the crates that the serverless endpoints depend on (here foo and bar) are not published, which would be the case if they are internal to the project.

Also, not having the Cargo.toml workspace root at the root of the project directory disables RLS, for code completion / formatting etc in VSCode.

I guess this is what people mean when they talk about lock-in with serverless, it's not so much about the platform, but the constraints they impose upon your project structure and dependency management.