4
use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod myepicproject {
  use super::*;
  pub fn start_stuff_off(ctx: Context<StartStuffOff>) -> ProgramResult {
    Ok(())
  }
}

#[derive(Accounts)]
pub struct StartStuffOff {}

I have the source rust code above and the error below.

error[E0412]: cannot find type `ProgramResult` in this scope
 --> programs/myepicproject/src/lib.rs:8:58
  |
8 |   pub fn start_stuff_off(ctx: Context<StartStuffOff>) -> ProgramResult {
  |                                                          ^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0412`.
error: could not compile `myepicproject` due to previous error

Have any suggestion?

Using Anchor

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
yeshealer
  • 93
  • 1
  • 2
  • 8
  • 3
    The last version with `ProgramResult` was `anchor_lang` v0.21.0 [It looks like from `0.22.0` and on you're supposed to use just `Result<()>` instead](https://github.com/project-serum/anchor/blob/master/CHANGELOG.md#breaking-1) – PitaJ Mar 21 '22 at 16:31
  • I used Result<()> instead ProgramResult. But have warning. I'm newbie on Rust development and this is the first step of my learning Rust. Please tell me more detail and specifically. – yeshealer Mar 21 '22 at 18:46
  • What is the warning that you are getting? As long as your compilation doesn't fail; the code should work as expected. Most warnings from the compiler will notify you when you violate best practices. – Cassie Mar 26 '22 at 02:40

2 Answers2

8

this solves the issue. you have to explicitly import it

use anchor_lang::solana_program::entrypoint::ProgramResult;
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
7

Try like that:

pub fn start_stuff_off(ctx: Context<StartStuffOff>) -> Result<()> {
bguiz
  • 27,371
  • 47
  • 154
  • 243
Anna
  • 96
  • 2